Releases: topaz-crystal/topaz
Default value for each column
Added Time support
Fixed a bug of time format for PostgreSQL
This release includes following topics.
- bug fix of time format for PostgreSQL.(See #3)
Install tool to build Kemal with Topaz
I'm happy to announce to release new tool that build a kemal project with topaz. 🎉
You can simply start with it like
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/topaz-crystal/topaz/master/tools/install.rb)"
This release includes bug fixes and refactoring.
Table migration!
Updates
- Support table migration!:tada: Doc
- Bug fixes (Especially for PostgreSQL)
Crystal 0.20.3, Nullable column, #to_json and #from_json
Suppoort Crystal version 0.20.3 🎉
Nullable column is accepted.(See below sample)
Support to_json and from_json(#json
is deprecated)
Topaz::Log.show_query
is now Topaz::Db.show_query
class NullableModel < Topaz::Model
columns(
name: String,
nullable: {type: String, nullable: true},
not_nullable: {type: String, nullable: false},
)
end
NullableModel.create("sample", nil, "not nullable")
Support transaction!
- Support transaction! 🎉 (Thanks @bcardiff)
join
is deprecated
See sample/transaction.cr as a sample code
[Sample code]
Topaz::Db.shared.transaction do |tx|
Sample.in(tx).create("sample0")
Sample.in(tx).create("sample1")
...
t0 = Sample.in(tx).find(1)
t0.in(tx).update(name: "sample0 updated")
end
Support PostgreSQL! Simplify core macros!
- Support PostgreSQL:tada: (Thanks @will and @asterite)
- Simplify core macros(columns, has_many, belongs_to)
primary
is deprecated (You have to control it on code level)
Example:
Previous
class Parent < Topaz::Model
columns(
{name: name, type: String}
)
has_many(
{model: Child, as: childlen, key: p_id}
)
end
Now
class Parent < Topaz::Model
columns(
name: String
)
has_many(
childlen: {model: Child, key: p_id}
)
end
Reducing database overhead and becoming stable
Version 0.1.0
Now Topaz is enough stable so that increment minor version from 0 to 1 🎉
Reduced Database overhead by keeping opening connection with it. Thanks @asterite !
Any issues or PRs are welcome :)
Added strong feature `json`
Converting models to jsons is a necessary feature for who develops api server.
Now your api easily generate and return jsons of models with Topaz.
For example, when we have
JsonParent(name)
- JsonChild(age, p_id)
- JsonToy(name, price, c_id)
- JsonPart(t_id)
- JsonPet(p_id)
Then we can write like
p = JsonParent.select.first
puts p.json
puts p.json({include: :childlen, except: :id})
puts p.json({include: {childlen: {except: [:id, :p_id]}, pets: nil} })
puts p.json({include: {childlen: {include: {toies: {include: :parts, only: :price} } }, pets: nil} })
We got
{"id": 1, "name": "John"}
{"name": "John", "childlen": [{"id": 1, "age": 12, "p_id": 1}, {"id": 2, "age": 15, "p_id": 1}, {"id": 3, "age": 23, "p_id": 1}]}
{"id": 1, "name": "John", "childlen": [{"age": 12}, {"age": 15}, {"age": 23}], "pets": [{"id": 1, "p_id": 1}, {"id": 2, "p_id": 1}, {"id": 3, "p_id": 1}, {"id": 4, "p_id": 1}]}
{"id": 1, "name": "John", "childlen": [{"id": 1, "age": 12, "p_id": 1, "toies": [{"price": 10, "parts": [{"id": 1, "t_id": 1}]}, {"price": 12, "parts": []}]}, {"id": 2, "age": 15, "p_id": 1, "toies": [{"price": 15, "parts": [{"id": 2, "t_id": 3}, {"id": 3, "t_id": 3}, {"id": 4, "t_id": 3}]}]}, {"id": 3, "age": 23, "p_id": 1, "toies": []}], "pets": [{"id": 1, "p_id": 1}, {"id": 2, "p_id": 1}, {"id": 3, "p_id": 1}, {"id": 4, "p_id": 1}]}