sql
sql copied to clipboard
A delightful SQL ORM ☺️
Just an idea. ```crystal module Onyx::SQL macro restrict(t, model, &block) {% for exp in block.body.expressions %} {% unless exp.is_a?(Call) && exp.name == "getter" %} {% raise "Must be getter" %}...
Currently this code can raise in runtime with `NilAssertionError` if `user.id` is `nil`. ```crystal class Use schema users do pkey id : Int32 end end class Post schema posts do...
Related to https://github.com/onyxframework/onyx/issues/18.
To be consistent with Query methods. May be a little tedious, though: ```crystal changeset = user.changeset changeset.set(updated_at: Time.now) ```
```crystal repo.exec(user.update(updated_at: Time.now)) ``` Doesn't work now, as `Model#update` requires `Changeset` argument.
```crystal Onyx::SQL.exec(user.update(changeset.update(foo: "bar"))) ```
Useful to query `Onyx::SQL::Serializable` objects with built queries.
Use-case – unknown structure JSON: ```crystal type payload : Hash(String, String), converter: PG::JSONB(Hash(String, String)) ``` Or unique enumerables as set: ```crystal type tags : Set(String), converter: PG::Set(String) ```
I do have code which requires models to be sorted persistently in different places. Primary key could act as a comparator value, even if it's UUID. See https://github.com/crystal-lang/crystal/pull/6611.