ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.
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:
Granite::Connections
array instead of Granite::Adapters
adapter
macro was renamed to connection
table_name
macro was renamed to table
field
macro was renamed to column
primary
macro was changed into a flag primary: true
on the column
macroid
field is no longer added by defaultcolumn
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:
exists?
class method (#343) by @Blacksmoke16belongs_to
to the resulting field (#323) by @Blacksmoke16Support default values (#312) @Blacksmoke16 Add colors to logged queries (#311) @Blacksmoke16 Implement #touch (#314) @Blacksmoke16 Support array IN queries with query builder (#313) @Blacksmoke16
add timezone support #310 - @icyleaf Association improvements #307 - @Blacksmoke16
Include clause when using custom select statement - #305 by @hfjallemark
Belongs_to refactor - #304 by @Blacksmoke16
Use env vars to specify sqlite version - #303 by @Blacksmoke16
Crystal 0.27.0 - #302 by @Blacksmoke16
Only define updated/created_at
properties if they are wanted - #301 by @Blacksmoke16
Fix Assembler#count - #299 by @c910335
Add support for AND and OR clause - #297 by @drujensen
Test PG11 on travis - #294 by @Blacksmoke16
Better UUID support - #293 by @Blacksmoke16
Query Builder support Mysql and Sqlite (#285) @drujensen Support PG Array Types (#286) @Blacksmoke16 Crystal 0.26.1 Support (#288) @Blacksmoke16 Annotation Support (#289) @Blacksmoke16 Extend Query Builder (#290) @drujensen Update Query Documentation (#292) @drujensen
Add limit and offset to QueryBuilder, mild refactoring (#284) @c910335 Refactored the validator helpers and added exclusion validator (#283) @Thellior add spaces (#281) @drujensen list the documentation instead of the docs directory (#280) @drujensen
Clear errors before validating models (#279) @yumoose
Breaking Changes
Dj/129 has many (#278) @drujensen
Dj/lazy load connection (#277) @drujensen Test multiple databases (#270) @Thellior Example for String foreign_key (#265) @winhackua Dj/271 maintain one database connection (#274) @drujensen Has one relationship (#264) @zaidakram Make the "through class" a symbol (#269) @Hansterdam
Targeting Crystal 0.26 (#268 thanks @robacarp) Fix time parsing on Crystal 26.0 (#267 thanks @msa7) Adapter Registration Support (#257 thanks @Blacksmoke16) add nodoc to granite methods generated by macros (#261 thanks @Blacksmoke16) Adds support for YAML::Serializable (#255 thanks @Blacksmoke16) Fix wording on dep install (#259 thanks @drinkmorewaters) Split docs into smaller files (#256 thanks @Blacksmoke16) Adds support for JSON::Serializable (#253 thanks @Blacksmoke16) - Breaking change fix conflicting use of query (#247 thanks @drujensen) - Breaking change Update database docker (#241 thanks @Thellior) Add ameba, fix style errors (#240 thanks @Thellior) Adding transaction save!, create!, destroy! methods (#232, thanks @Thellior)