API of crystal_api
December 2, 2016 ยท View on GitHub
Global functions
Connect to database [REQUIRED]
Configure Kemal Postgresql middleware and adds to middleware stack. Should be executed at the beginning of application.
pg_connect_from_yaml(yaml_file, capacity = 25, timeout = 0.1)
yaml_file- path to database configuration file like example below:capacitytimeout
host: localhost
database: crystal
user: crystal_user
password: crystal_password
Define a model
Model is a struct used to store and use database row. It is lower level ORM.
crystal_model(ModelName, field : Type, ...)
ModelName- example: Event, User, Paymentfield- name of field, example: id, name, email, created_atType- type of data, example: String, Int32
Notes:
- If you want to use
idyou must addidas a field. - Fields need to be hardcoded not fetched from table structure.
Example:
crystal_model(EventModel, id : Int32, name : String)
Full REST JSON API
crystal_resource_full_rest(event, events, events, EventModel)
Model
Model#reload
u = User.fetch_one({"id" => 1})
# ...
u = u.reload
Model#update
u = User.fetch_one({"id" => 1})
u = u.update({"name" => "New Name"})
u.name
# => "New Name"
Is it ready?
Not yet.