mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
64391efa4d
* add mysql to orm * fix got to big packet error * format sql.v * format example * custom sql types * add mysql table cration * add documentation * format sql.v * fix markdown * start implementing select_expr for mysql * remove orm.c * format sql.v * finish mysql expr * remove c * remove unessecary files * change to c implementation * remove c * added str interpolation for idents * fix string insert * fix compilation problems * fix gitly compilation * fix typing mistake * add link to orm docs
81 lines
1.1 KiB
V
81 lines
1.1 KiB
V
import sqlite
|
|
import mysql
|
|
|
|
struct Module {
|
|
id int [primary; sql: serial]
|
|
name string
|
|
nr_downloads int [sql: u64]
|
|
creator User
|
|
}
|
|
|
|
struct User {
|
|
id int [primary; sql: serial]
|
|
age int
|
|
name string [nonull]
|
|
is_customer bool
|
|
skipped_string string [skip]
|
|
}
|
|
|
|
fn main() {
|
|
db := sqlite.connect(':memory:') or { panic(err) }
|
|
db.exec('drop table if exists User')
|
|
sql db {
|
|
create table Module
|
|
}
|
|
|
|
mod := Module{
|
|
name: 'test'
|
|
nr_downloads: 10
|
|
creator: User{
|
|
age: 21
|
|
name: 'VUser'
|
|
is_customer: true
|
|
}
|
|
}
|
|
sql db {
|
|
insert mod into Module
|
|
}
|
|
|
|
modul := sql db {
|
|
select from Module where id == 1
|
|
}
|
|
|
|
eprintln(modul)
|
|
|
|
mysql()
|
|
}
|
|
|
|
fn mysql() {
|
|
mut conn := mysql.Connection{
|
|
host: 'localhost'
|
|
port: 3306
|
|
username: 'root'
|
|
password: 'abc'
|
|
dbname: 'test'
|
|
}
|
|
conn.connect() or { panic(err) }
|
|
|
|
sql conn {
|
|
create table Module
|
|
}
|
|
|
|
mod := Module{
|
|
name: 'test'
|
|
nr_downloads: 10
|
|
creator: User{
|
|
age: 21
|
|
name: 'VUser'
|
|
is_customer: true
|
|
}
|
|
}
|
|
|
|
sql conn {
|
|
insert mod into Module
|
|
}
|
|
|
|
m := sql conn {
|
|
select from Module where id == 1
|
|
}
|
|
eprintln(m)
|
|
}
|