-
-
Save dom96/de15982f0e871e83f467fa06e3d8e284 to your computer and use it in GitHub Desktop.
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
import | |
std / [options, logging, with] | |
import | |
norm / [model, sqlite] | |
addHandler newConsoleLogger(fmtStr = "") | |
type | |
User* = ref object of Model | |
email*: string | |
Customer* = ref object of Model | |
name*: Option[string] | |
user*: User | |
func newUser*(email = ""): User = | |
User(email: email) | |
func newCustomer*(name = none string; user = newUser()): Customer = | |
Customer(name: name, user: user) | |
let dbConn* = open(":memory:", "", "", "") | |
dbConn.createTables(newCustomer()) | |
var | |
userFoo = newUser("foo@foo.foo") | |
userBar = newUser("bar@bar.bar") | |
alice = newCustomer(some "Alice", userFoo) | |
bob = newCustomer(some "Bob", userFoo) | |
sam = newCustomer(some "Sam", userBar) | |
aliceAndBob = [alice, bob] | |
with dbConn: | |
insert aliceAndBob | |
insert userBar | |
insert sam | |
var customerBar = newCustomer() | |
dbConn.select(customerBar, "User.email = ?", "bar@bar.bar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment