Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Jun 10, 2022
1 parent 69e0383 commit de83efa
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/orm.v
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)
}
}
45 changes: 45 additions & 0 deletions vsql/orm.v
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')
}

0 comments on commit de83efa

Please sign in to comment.