1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/orm
2021-04-11 23:57:25 +02:00
..
orm_test.v orm: add != (#9600) 2021-04-08 02:13:25 +02:00
README.md orm: add unique fields & add drop table stmt (#9684) 2021-04-11 23:57:25 +02:00

ORM

Attributes

Fields

  • [primary] sets the field as the primary key
  • [unique] sets the field as unique
  • [unique: 'foo'] adds the field to a unique group
  • [nonull] field will be NOT NULL in table creation
  • [skip] field will be skipped
  • [sql: type] sets the type which is used in sql (special type serial)

Usage

struct Foo {
    id   int    [primary; sql: serial]
    name string [nonull]
}

Create

sql db {
    create table Foo
}

Drop

sql db {
    drop table Foo
}

Insert

var := Foo{
    name: 'abc'
}

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
}