clear v0.9 Release Notes

Release Date: 2020-11-22 // over 3 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 to Collection#append_operation
    • โž• Add Clear::SQL.after_commit method

    Register a callback function which will be fired once when SQL COMMIT
    operation is called

    This 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( } 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|\_now } end

    Note: before(:commit) and after(: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.
    Your CustomType must be JSON::Serializable, and the database column
    must be of type jsonb, json or text.

    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 over jsonb 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 each ASC to DESC direction, and each NULLS FIRST to NULLS LAST

    ๐Ÿ›  Bugfixes

    • Prepare the code to make it compatible with crystal 1.0. Change Void to Nil
    • first and last 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