-
Notifications
You must be signed in to change notification settings - Fork 18
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
69e0383
commit de83efa
Showing
2 changed files
with
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import vsql | ||
import orm | ||
|
||
fn main() { | ||
os.rm('test.vsql') or {} | ||
example() or { panic(err) } | ||
} | ||
|
||
struct Product { | ||
id int [primary] | ||
product_name string [sql: 'varchar(100)'] | ||
price f32 | ||
} | ||
|
||
fn example() ? { | ||
mut db := *(vsql.open('test.vsql') ?) | ||
|
||
// if db is orm.Connection { | ||
// } | ||
|
||
sql db { | ||
create table Product | ||
} | ||
|
||
products := [ | ||
Product{ | ||
id: 1 | ||
product_name: 'Ice Cream' | ||
price: 5.99 | ||
} | ||
Product{ | ||
id: 2 | ||
product_name: 'Ham Sandwhich' | ||
price: 3.47 | ||
} | ||
Product{ | ||
id: 3 | ||
product_name: 'Bagel' | ||
price: 1.25 | ||
} | ||
] | ||
|
||
for product in products { | ||
sql db { | ||
insert product into Product | ||
} | ||
} | ||
|
||
result := sql db { | ||
select from Product where price > 2 | ||
} | ||
|
||
for row in result { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// orm.v implements the V language ORM: https://modules.vlang.io/orm.html | ||
|
||
module vsql | ||
|
||
import orm | ||
|
||
/* | ||
interface Connection { | ||
@select(config SelectConfig, data QueryData, where QueryData) ?[][]Primitive | ||
insert(table string, data QueryData) ? | ||
update(table string, data QueryData, where QueryData) ? | ||
delete(table string, where QueryData) ? | ||
create(table string, fields []TableField) ? | ||
drop(table string) ? | ||
last_id() Primitive | ||
} | ||
*/ | ||
|
||
pub fn (c &Connection) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ?[][]orm.Primitive { | ||
panic('select') | ||
} | ||
|
||
pub fn (c &Connection) insert(table string, data orm.QueryData) ? { | ||
panic('insert') | ||
} | ||
|
||
pub fn (c &Connection) update(table string, data orm.QueryData, where orm.QueryData) ? { | ||
panic('update') | ||
} | ||
|
||
pub fn (c &Connection) delete(table string, where orm.QueryData) ? { | ||
panic('delete') | ||
} | ||
|
||
pub fn (c &Connection) create(table string, fields []orm.TableField) ? { | ||
panic('create') | ||
} | ||
|
||
pub fn (c &Connection) drop(table string) ? { | ||
panic('drop') | ||
} | ||
|
||
pub fn (c &Connection) last_id() orm.Primitive { | ||
panic('last_id') | ||
} |