Skip to content

Crystal 0.30.0 and DSL breaking changes

Compare
Choose a tag to compare
@drujensen drujensen released this 07 Aug 03:44
· 78 commits to master since this release
a866c10

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
  • 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 field
end

Other changes: