granite-orm v0.17.0 Release Notes

Release Date: 2019-08-07 // over 4 years ago
  • 🚀 This release has some significant breaking changes to the DSL and leverages Annotations instead of the mutable constants and final macros. @Blacksmoke16 spent many months researching the use of Annotations and has overhauled Granite to take advantage of them.

    In the process, we have decided to change the DSL to be more database centric. Here is a list of the breaking changes:

    • Adapters are now added to Granite::Connections array instead of Granite::Adapters
    • the adapter macro was renamed to connection
    • the table_name macro was renamed to table
    • the field macro was renamed to column
    • the primary macro was changed into a flag primary: true on the column macro
    • 0️⃣ a primary id field is no longer added by default
    • a column can be declared as Nilable using ?

    Here is an example of how to register a new connection:

    Granite::Connections \<\< Granite::Adapter::Mysql.new(name: "mysql", url: "YOUR\_DATABASE\_URL")
    

    Here is an example of a model:

    require "granite/adapter/mysql"class Post \< Granite::Base connection mysql table posts # Name of the table to use for the model, defaults to class name snake cased column id : Int64, primary: true # Primary key, defaults to AUTO INCREMENT column name : String? # Nilable field column body : String # Not nil fieldend
    

    Other changes: