|
| 1 | +# v0.9 |
| 2 | + |
| 3 | +I'm pleased to announce the version 0.9 of Crystal Clear ORM ! |
| 4 | +This version is probably the biggest version released since Clear is born. |
| 5 | + |
| 6 | +Under the hood, it simplifies a lot of code, push testing to another level with |
| 7 | +a great amount of new specs. |
| 8 | + |
| 9 | +On the feature part, it add full support for serializing to and from json, with mass assignment secure check, big decimal |
| 10 | +type, PostgreSQL view management at migration, new callbacks methods, support for postgres interval object and so on... |
| 11 | + |
| 12 | +Finally, the code has been tweaked to be compatible with release of Crystal 1.0. |
| 13 | + |
| 14 | +With that in mind, Clear starts to mature, with only CLI, polymorphic relations and model inheritance still lacking. |
| 15 | + |
| 16 | +_Note of warning_: some changes will break your code. However everything can be fixed in matter of minutes (hopefully) |
| 17 | + |
| 18 | +Special thanks to all contributors of this version: |
| 19 | + |
| 20 | +@007lva @anykeyh @GabFitzgerald @dukeraphaelng @mamantoha @watzon @yujiri8 |
| 21 | + |
| 22 | +(hopefully I did not forget someone) |
| 23 | + |
| 24 | +## Breaking changes |
| 25 | + |
| 26 | +- `Clear::SQL::ConnectionPool` now returns DB::Connection instead of DB::Database (fix #177) |
| 27 | +- `Clear::Migration::Direction` is now an enum instead of a struct. |
| 28 | +- where and having clauses use splat and named tuple always. This is breaking change. |
| 29 | + - Before you had to do: |
| 30 | + |
| 31 | + ```crystal |
| 32 | + where("a = ?", [1]) |
| 33 | + ``` |
| 34 | + |
| 35 | + Now you can do much more easy: |
| 36 | + |
| 37 | + ```crystal |
| 38 | + where("a = ?", 1) |
| 39 | + ``` |
| 40 | + |
| 41 | + Same apply for the named parameters version: |
| 42 | + |
| 43 | + ```crystal |
| 44 | + # Instead of |
| 45 | + where("a = :a", { a: 1 } ) |
| 46 | + # Do |
| 47 | + where("a = :a", a: 1) |
| 48 | + ``` |
| 49 | + |
| 50 | + |
| 51 | +## Features |
| 52 | + |
| 53 | +- PR #187 Add methods to import from and to `json`, with mass_assignment security |
| 54 | + (thanks @dukeraphaelng and Caspian Baska for this awesome work!) |
| 55 | +- PR #191 Add Big Decimal support (@dukeraphaelng) |
| 56 | +- `Collection#add_operation` has been renamed to `Collection#append_operation` |
| 57 | +- Add `Clear::SQL.after_commit` method |
| 58 | + |
| 59 | +Register a callback function which will be fired once when SQL `COMMIT` |
| 60 | +operation is called |
| 61 | + |
| 62 | +This can be used for example to send email, or perform others tasks |
| 63 | +when you want to be sure the data is secured in the database. |
| 64 | + |
| 65 | +```crystal |
| 66 | + transaction do |
| 67 | + @user = User.find(1) |
| 68 | + @user.subscribe! |
| 69 | + Clear::SQL.after_commit{ Email.deliver(ConfirmationMail.new(@user)) } |
| 70 | + end |
| 71 | +``` |
| 72 | + |
| 73 | +In case the transaction fail and eventually rollback, the code won't be called. |
| 74 | + |
| 75 | +Same method exists now on the model level, using before and after hooks: |
| 76 | + |
| 77 | +```crystal |
| 78 | + class User |
| 79 | + include Clear::Model |
| 80 | +
|
| 81 | + after(:commit){ |mdl| WelcomeEmail.new(mdl.as(User)).deliver_now } |
| 82 | + end |
| 83 | +``` |
| 84 | + |
| 85 | +Note: `before(:commit)` and `after(:commit)` are both called after the transaction has been commited. |
| 86 | + Before hook always call before after hook. |
| 87 | + |
| 88 | +- Add possibility to name and rollback to a specific savepoint: |
| 89 | + |
| 90 | +```crystal |
| 91 | + Clear::SQL.with_savepoint("a") do |
| 92 | + Clear::SQL.with_savepoint("b") do |
| 93 | + Clear::SQL.rollback("a") # < Exit to "a" |
| 94 | + end |
| 95 | + puts "This won't be called" |
| 96 | + end |
| 97 | + puts "This will be called" |
| 98 | +``` |
| 99 | + |
| 100 | +- Add `Clear.json_serializable_converter(CustomType)` |
| 101 | + |
| 102 | +This macro help setting a converter transparently for any `CustomType`. |
| 103 | +Your `CustomType` must be `JSON::Serializable`, and the database column |
| 104 | +must be of type `jsonb`, `json` or `text`. |
| 105 | + |
| 106 | +```crystal |
| 107 | + class Color |
| 108 | + include JSON::Serializable |
| 109 | +
|
| 110 | + @[JSON::Field]; property r: Int8 |
| 111 | + @[JSON::Field]; property g: Int8 |
| 112 | + @[JSON::Field]; property b: Int8 |
| 113 | + @[JSON::Field]; property a: Int8 |
| 114 | + end |
| 115 | +
|
| 116 | + Clear.json_serializable_converter(Color) |
| 117 | +
|
| 118 | + # Now you can use Color in your models: |
| 119 | +
|
| 120 | + class MyModel |
| 121 | + include Clear::Model |
| 122 | +
|
| 123 | + column color : Color |
| 124 | + end |
| 125 | +``` |
| 126 | + |
| 127 | +- Add `jsonb().contains?(...)` method |
| 128 | + |
| 129 | +This allow usage of Postgres `?` operator over `jsonb` fields: |
| 130 | + |
| 131 | +```crystal |
| 132 | + # SELECT * FROM actors WHERE "jsonb_column"->'movies' ? 'Top Gun' LIMIT 1; |
| 133 | + Actor.query.where{ var("jsonb_column").jsonb("movies").contains?("Top Gun") }.first!.name # << Tom Cruise |
| 134 | +``` |
| 135 | + |
| 136 | +- Add `SelectQuery#reverse_order_by` method |
| 137 | + |
| 138 | +A convenient method to reverse all the order by clauses, |
| 139 | +turning each `ASC` to `DESC` direction, and each `NULLS FIRST` to `NULLS LAST` |
| 140 | + |
| 141 | + |
| 142 | +## Bugfixes |
| 143 | + |
| 144 | +- Prepare the code to make it compatible with crystal 1.0. Change `Void` to `Nil` |
| 145 | +- `first` and `last` on collection object does not change the collection anymore (previously would add limit/offset and change order_by clauses) |
| 146 | +- Dozen of other bugs not tracked here have been fixed, by usage or new test sets. |
| 147 | + |
1 | 148 | # v0.8 |
2 | 149 |
|
3 | 150 | ## Features |
@@ -29,30 +176,30 @@ query = Mode.query.select( Clear::SQL.raw("CASE WHEN x=? THEN 1 ELSE 0 END as ch |
29 | 176 |
|
30 | 177 | ## Features |
31 | 178 |
|
32 | | -- Add `Clear::Interval` type |
| 179 | +- Add support for `PG::Interval` type |
33 | 180 |
|
34 | | -This type is related to the type `Clear::Interval` of PostgreSQL. It stores `month`, `days` and `microseconds` and can be used |
| 181 | +This type is related to the type `PG::Interval` of PostgreSQL. It stores `month`, `days` and `microseconds` and can be used |
35 | 182 | with `Time` (Postgres' `datetime`) by adding or substracting it. |
36 | 183 |
|
37 | 184 | ### Examples: |
38 | 185 |
|
39 | 186 | Usage in Expression engine: |
40 | 187 |
|
41 | 188 | ```crystal |
42 | | -interval = Clear::Interval.new(months: 1, days: 1) |
| 189 | +interval = PG::Interval.new(months: 1, days: 1) |
43 | 190 |
|
44 | 191 | MyModel.query.where{ created_at - interval > updated_at }.each do |model| |
45 | 192 | # ... |
46 | 193 | end |
47 | 194 | ``` |
48 | 195 |
|
49 | | -It might be used as column definition, and added / removed to crystal `Time` object |
| 196 | +It might be used as column definition as well. |
50 | 197 |
|
51 | 198 | ```crystal |
52 | 199 | class MyModel |
53 | 200 | include Clear::Model |
54 | 201 |
|
55 | | - column i : Clear::Interval |
| 202 | + column i : PG::Interval |
56 | 203 | end |
57 | 204 |
|
58 | 205 | puts "Expected time: #{Time.local + MyModel.first!.i}" |
@@ -257,7 +404,7 @@ Basically a transition version, to support Crystal 0.27. Some of the features of |
257 | 404 |
|
258 | 405 | ## Breaking changes |
259 | 406 | - `Model#save` on read only model do not throw exception anymore but return false (save! still throw error) |
260 | | -- `with_serial_pkey` use Int32 (type `:serial`) and Int64 (type `:longserial`) pkey instead of UInt32 and UInt64. This would prevent issue with default `belongs_to` behavior and simplify static number assignation. |
| 407 | +- `with_serial_pkey` use Int32 (type `:serial`) and Int64 (type `:longserial`) primary key instead of `UInt32` and `UInt64`. This would prevent issue with default `belongs_to` behavior and simplify static number assignation. |
261 | 408 |
|
262 | 409 | # v0.2 |
263 | 410 |
|
@@ -300,7 +447,7 @@ Basically a transition version, to support Crystal 0.27. Some of the features of |
300 | 447 |
|
301 | 448 | ## Bugfixes |
302 | 449 |
|
303 | | -- Patching segfault caused by weird architecture choice of mine over the `pkey` method. |
| 450 | +- Patching segfault caused by weird architecture choice of mine over the `__pkey__` method. |
304 | 451 | - Fix issue with delete if the primary key is not `id` |
305 | 452 | - Add watchdog to disallow inclusion of `Clear::Model` on struct objects, which |
306 | 453 | is not intended to work. |
|
0 commit comments