-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DO NOT MERGE. This is partial support for the ORM. However, there are some challenges that need to be addressed before this can be properly reviewed and landed: 1. The ORM in V requires drivers to be hard-coded. See #90. 2. The Connection doesn't _really_ implement orm.Connection because the vsql Connection is required to be mut and the current interface definition does not allow this. 3. We need to create a new test suite for the ORM. `vsql/orm_test.v` filled with combinations of statements "sql" commands will work just fine. Specifically, we need to test different combinations of expressions and types. Fixes #90
- Loading branch information
1 parent
061e53a
commit 8d76f33
Showing
6 changed files
with
337 additions
and
50 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,43 @@ | ||
import os | ||
import vsql | ||
|
||
fn main() { | ||
os.rm('test.vsql') or {} | ||
example() or { panic(err) } | ||
} | ||
|
||
struct Product { | ||
id int @[primary] | ||
product_name string @[sql_type: 'varchar(100)'] | ||
price f64 | ||
} | ||
|
||
fn (p Product) str() string { | ||
return '${p.product_name} ($${p.price})' | ||
} | ||
|
||
fn example() ! { | ||
mut db := vsql.open_orm('test.vsql')! | ||
|
||
sql db { | ||
create table Product | ||
}! | ||
|
||
products := [ | ||
Product{1, 'Ice Cream', 5.99}, | ||
Product{2, 'Ham Sandwhich', 3.47}, | ||
Product{3, 'Bagel', 1.25}, | ||
] | ||
for product in products { | ||
sql db { | ||
insert product into Product | ||
}! | ||
} | ||
|
||
println("Products over $2:") | ||
for row in sql db { | ||
select from Product where price > 2 | ||
}! { | ||
println(row) | ||
} | ||
} |
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
Oops, something went wrong.