mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Merge 45d55ba473
into 532ae075bd
This commit is contained in:
commit
58c4c2ad6a
2 changed files with 29 additions and 1 deletions
|
@ -104,6 +104,23 @@ struct ModelWithEnum
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Ensure types that happen to have the same name as types within the `DB`
|
||||||
|
# namespace don't clash here
|
||||||
|
struct Transaction
|
||||||
|
include DB::Serializable
|
||||||
|
|
||||||
|
@[DB::Field(key: "c0")]
|
||||||
|
getter id : Int32
|
||||||
|
@[DB::Field(key: "c1")]
|
||||||
|
getter status : Status
|
||||||
|
|
||||||
|
enum Status
|
||||||
|
Pending
|
||||||
|
Complete
|
||||||
|
Canceled
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
macro from_dummy(query, type)
|
macro from_dummy(query, type)
|
||||||
with_dummy do |db|
|
with_dummy do |db|
|
||||||
rs = db.query({{ query }})
|
rs = db.query({{ query }})
|
||||||
|
@ -206,6 +223,13 @@ describe "DB::Serializable" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should compile when top-level names collide with DB-namespaced names" do
|
||||||
|
expect_model("1,Pending", Transaction, {
|
||||||
|
id: 1,
|
||||||
|
status: Transaction::Status::Pending,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
it "should initialize multiple instances from a single resultset" do
|
it "should initialize multiple instances from a single resultset" do
|
||||||
with_dummy do |db|
|
with_dummy do |db|
|
||||||
db.query("1,a 2,b") do |rs|
|
db.query("1,a 2,b") do |rs|
|
||||||
|
|
|
@ -109,7 +109,11 @@ module DB
|
||||||
{% unless ann && ann[:ignore] %}
|
{% unless ann && ann[:ignore] %}
|
||||||
{%
|
{%
|
||||||
properties[ivar.id] = {
|
properties[ivar.id] = {
|
||||||
type: ivar.type,
|
type: if ivar.type.union?
|
||||||
|
"Union(#{ivar.type.union_types.map { |t| "::#{t}".id }.join(" | ").id})".id
|
||||||
|
else
|
||||||
|
"::#{ivar.type}".id
|
||||||
|
end,
|
||||||
key: ((ann && ann[:key]) || ivar).id.stringify,
|
key: ((ann && ann[:key]) || ivar).id.stringify,
|
||||||
default: ivar.default_value,
|
default: ivar.default_value,
|
||||||
nilable: ivar.type.nilable?,
|
nilable: ivar.type.nilable?,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue