Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92a22e9
commit b8e070b
Showing
5 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sqlite | ||
|
||
struct Parent { | ||
id int [primary; sql: serial] | ||
name string | ||
chields []Chield [fkey: 'parent_id'] | ||
} | ||
|
||
struct Chield { | ||
id int [primary; sql: serial] | ||
parent_id int | ||
name string | ||
} | ||
|
||
fn test_orm_array() { | ||
mut db := sqlite.connect(':memory:') or { panic(err) } | ||
sql db { | ||
create table Parent | ||
} | ||
|
||
par := Parent{ | ||
name: 'test' | ||
chields: [ | ||
Chield{ | ||
name: 'abc' | ||
}, | ||
Chield{ | ||
name: 'def' | ||
}, | ||
] | ||
} | ||
|
||
sql db { | ||
insert par into Parent | ||
} | ||
|
||
parent := sql db { | ||
select from Parent where id == 1 | ||
} | ||
|
||
sql db { | ||
drop table Chield | ||
drop table Parent | ||
} | ||
|
||
assert parent.name == par.name | ||
assert parent.chields.len == par.chields.len | ||
assert parent.chields[0].name == 'abc' | ||
assert parent.chields[1].name == 'def' | ||
} |