clear v0.9 Release Notes
Release Date: 2020-11-22 // over 4 years ago-
v0.9
I'm pleased to announce the version 0.9 of Crystal Clear ORM !
๐ This version is probably the biggest version released since Clear is born.โ Under the hood, it simplifies a lot of code, push testing to another level with
a great amount of new specs.๐ On the feature part, it add full support for serializing to and from json, with mass assignment secure check, big decimal
๐ type, PostgreSQL view management at migration, new callbacks methods, support for postgres interval object and so on...๐ Finally, the code has been tweaked to be compatible with release of Crystal 1.0.
With that in mind, Clear starts to mature, with only CLI, polymorphic relations and model inheritance still lacking.
โ Note of warning: some changes will break your code. However everything can be fixed in matter of minutes (hopefully)
Special thanks to all contributors of this version:
@007lva @anykeyh @GabFitzgerald @dukeraphaelng @mamantoha @watzon @yujiri8
(hopefully I did not forget someone)
๐ฅ Breaking changes
Clear::SQL::ConnectionPool
now returns DB::Connection instead of DB::Database (fix #177)Clear::Migration::Direction
is now an enum instead of a struct.where and having clauses use splat and named tuple always. This is breaking change.
Before you had to do:
where("a = ?", [1])
Now you can do much more easy:
where("a = ?", 1)
Same apply for the named parameters version:
# Instead of where("a = :a", { a: 1 } ) # Do where("a = :a", a: 1)
๐ Features
- ๐ PR #187 Add methods to import from and to
json
, with mass_assignment security
(thanks @dukeraphaelng and Caspian Baska for this awesome work!) - ๐ PR #191 Add Big Decimal support (@dukeraphaelng)
Collection#add_operation
has been renamed toCollection#append_operation
- โ Add
Clear::SQL.after_commit
method
Register a callback function which will be fired once when SQL
COMMIT
operation is calledThis can be used for example to send email, or perform others tasks
when you want to be sure the data is secured in the database.transaction do@user = User.find(1) @user.subscribe! Clear::SQL.after\_commit{ Email.deliver(ConfirmationMail.new(@user)) } end
โช In case the transaction fail and eventually rollback, the code won't be called.
Same method exists now on the model level, using before and after hooks:
class Userinclude Clear::Model after(:commit){ |mdl| WelcomeEmail.new(mdl.as(User)).deliver\_now } end
Note:
before(:commit)
andafter(:commit)
are both called after the transaction has been commited.
Before hook always call before after hook.โ Add possibility to name and rollback to a specific savepoint:
Clear::SQL.with_savepoint("a") doClear::SQL.with_savepoint("b") doClear::SQL.rollback("a") # < Exit to "a"endputs "This won't be called"endputs "This will be called"
Add
Clear.json_serializable_converter(CustomType)
This macro help setting a converter transparently for any
CustomType
.
YourCustomType
must beJSON::Serializable
, and the database column
must be of typejsonb
,json
ortext
.class Colorinclude JSON::Serializable @[JSON::Field]; property r: Int8 @[JSON::Field]; property g: Int8 @[JSON::Field]; property b: Int8 @[JSON::Field]; property a: Int8endClear.json\_serializable\_converter(Color) # Now you can use Color in your models:class MyModelinclude Clear::Model column color : Colorend
- โ Add
jsonb().contains?(...)
method
This allow usage of Postgres
?
operator overjsonb
fields:# SELECT \* FROM actors WHERE "jsonb\_column"-\>'movies' ? 'Top Gun' LIMIT 1;Actor.query.where{ var("jsonb\_column").jsonb("movies").contains?("Top Gun") }.first!.name # \<\< Tom Cruise
- Add
SelectQuery#reverse_order_by
method
A convenient method to reverse all the order by clauses,
turning eachASC
toDESC
direction, and eachNULLS FIRST
toNULLS LAST
๐ Bugfixes
- Prepare the code to make it compatible with crystal 1.0. Change
Void
toNil
first
andlast
on collection object does not change the collection anymore (previously would add limit/offset and change order_by clauses)- โ Dozen of other bugs not tracked here have been fixed, by usage or new test sets.
Previous changes from v0.8
-
This version fix a lot of small things:
- ๐ Fix TimeInDay issues
- ๐ Fix issue when using DISTINCT with JOIN in models with custom SELECT
clause defined AFTER the joins. - ๐ Fix mistake in spec and add specs
- โ Add changelog; update shard
- โ Add seed command in the CLI
- โ add
or_where
feature - ๐ Fix FTS to remove ambiguous clauses
- ๐ Fix issue with nilable belongs_to which cannot be saved when set to nil
- โ Add RFC3339 support while converting string to time
- ๐ Fix caching with belongs_to
- โ Add colorize parameter to Clear::SQL::Logger module
- Migration: Add datatype conversion in add_column and alter_column methods
- โก๏ธ Migration: Update migration add_column operation to allow contraints, nullable
0๏ธโฃ and default value - โก๏ธ Update to latest version of pg gem
- Fix ambigous column name in with_xxx method for belongs_to relation
- โ Add possibility to have nulls first and nulls last in
order_by
method - ๐ง WIP on a SQL parser
- โ Add the possibility to convert from Array(JSON:Any)
- ๐ Fix misc typos