mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
.. | ||
orm_fn_test.v | ||
orm_test.v | ||
orm.v | ||
README.md |
ORM
Attributes
Structs
[table: 'name']
sets a custom table name
Fields
[primary]
sets the field as the primary key[unique]
sets the field as unique[unique: 'foo']
adds the field to a unique group[skip]
field will be skipped[sql: type]
wheretype
is a V type such asint
orf64
, or special typeserial
[sql: 'name']
sets a custom column name for the field[sql_type: 'SQL TYPE']
sets the sql type which is used in sql
Usage
struct Foo {
id int [primary; sql: serial]
name string [nonull]
created_at time.Time [sql_type: 'DATETIME']
updated_at string [sql_type: 'DATETIME']
deleted_at time.Time
}
Create
sql db {
create table Foo
}
Drop
sql db {
drop table Foo
}
Insert
var := Foo{
name: 'abc'
created_at: time.now()
updated_at: time.now().str()
deleted_at: time.now()
}
sql db {
insert var into Foo
}
Update
sql db {
update Foo set name = 'cde' where name == 'abc'
}
Delete
sql db {
delete from Foo where id > 10
}
Select
result := sql db {
select from Foo where id == 1
}
result := sql db {
select from Foo where id > 1 limit 5
}
result := sql db {
select from Foo where id > 1 order by id
}