Crystal 0.30.0 and DSL breaking changes
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 ofGranite::Adapters
- the
adapter
macro was renamed toconnection
- the
table_name
macro was renamed totable
- the
field
macro was renamed tocolumn
- the
primary
macro was changed into a flagprimary: true
on thecolumn
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:
- a866c10 Crystal v0.30.0 support (#354) by @bcardiff
- 9a2d4fe Count group by fixed (#352) by @unequaled86
- bdb879f Port Granite to use Annotations (#346) by @Blacksmoke16
- ce37f7a require "uuid" in fields.cr (#350) by @EnricoMonese
- c4bc435 Update CRUD delete example code (#348) by @EnricoMonese
- b2754fc replace @@var with their getter (#345) by @Blacksmoke16
- 6f2e6a3 Adds an
exists?
class method (#343) by @Blacksmoke16 - 82cb04e Support custom field types (#342) by @Blacksmoke16
- bc68440 Disallow union types (#341) by @Blacksmoke16