v/vlib/orm
Louis Schmieder 5df3d8ac75
orm: mysql fixes (#14772)
2022-06-16 20:19:49 +03:00
..
README.md doc: tablename -> table (#10359) 2021-06-08 00:48:42 +03:00
orm.v orm: mysql fixes (#14772) 2022-06-16 20:19:49 +03:00
orm_fn_test.v orm: do not order by default, ordering is slow; also fix a bug for tables without defined primary keys 2021-12-23 16:43:22 +02:00
orm_test.v orm: mysql fixes (#14772) 2022-06-16 20:19:49 +03:00

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] sets the type which is used in sql (special type serial)
  • [sql: 'name'] sets a custom column name for the field

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
}