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:capacity
timeout
host: localhost
database: crystal
user: crystal_user
password: crystal_password
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
id
you must addid
as a field. - Fields need to be hardcoded not fetched from table structure.
Example:
crystal_model(EventModel, id : Int32, name : String)
crystal_resource_full_rest(event, events, events, EventModel)
u = User.fetch_one({"id" => 1})
# ...
u = u.reload
u = User.fetch_one({"id" => 1})
u = u.update({"name" => "New Name"})
u.name
# => "New Name"
Not yet.