forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orm: add
references
attribute to allow foreign key declarations on …
…fields (vlang#19349)
- Loading branch information
1 parent
3f1c601
commit 79bae99
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import db.sqlite | ||
|
||
struct Boat { | ||
id int [primary; sql: serial] | ||
color_id int [references] | ||
another1_id int [references: 'size'] | ||
another2_id int [references: 'size(secondary_id)'] | ||
} | ||
|
||
struct Color { | ||
id int [primary; sql: serial] | ||
hex string | ||
} | ||
|
||
struct Size { | ||
id int [primary; sql: serial] | ||
secondary_id int | ||
} | ||
|
||
fn test_references_constraint() { | ||
db := sqlite.connect(':memory:') or { panic(err) } | ||
|
||
sql db { | ||
create table Boat | ||
create table Color | ||
create table Size | ||
} or { panic(err) } | ||
|
||
// this pragma returns a row for each foreign key constraint on a table | ||
pragma_result := db.exec('pragma foreign_key_list(boat)') or { panic('nope') } | ||
|
||
assert pragma_result.len == 3 | ||
} |