-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orm: allow using connections, that were explicitly casted to `orm.Con…
…nection` too (#17427)
- Loading branch information
walking devel
authored
Feb 27, 2023
1 parent
864e199
commit b7b6c23
Showing
3 changed files
with
56 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import db.sqlite | ||
import orm | ||
|
||
struct User { | ||
id int [primary; sql: serial] | ||
name string | ||
} | ||
|
||
fn test_orm_interface() { | ||
sqlite_db := sqlite.connect(':memory:') or { panic(err) } | ||
db := orm.Connection(sqlite_db) | ||
|
||
sql db { | ||
create table User | ||
} | ||
|
||
user := User{ | ||
name: 'test' | ||
} | ||
|
||
sql db { | ||
insert user into User | ||
} | ||
|
||
users := sql db { | ||
select from User | ||
} | ||
|
||
assert users.len == 1 | ||
assert users.first().name == user.name | ||
} |
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