mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: add mysql support (#9630)
* 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
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import sqlite
|
||||
import mysql
|
||||
|
||||
struct Module {
|
||||
id int
|
||||
id int [primary; sql: serial]
|
||||
name string
|
||||
nr_downloads int
|
||||
nr_downloads int [sql: u64]
|
||||
creator User
|
||||
}
|
||||
|
||||
struct User {
|
||||
id int
|
||||
id int [primary; sql: serial]
|
||||
age int
|
||||
name string
|
||||
name string [nonull]
|
||||
is_customer bool
|
||||
skipped_string string [skip]
|
||||
}
|
||||
@@ -18,8 +19,9 @@ struct User {
|
||||
fn main() {
|
||||
db := sqlite.connect(':memory:') or { panic(err) }
|
||||
db.exec('drop table if exists User')
|
||||
db.exec("create table Module (id integer primary key, name text default '', nr_downloads int default 0, creator int default 0);")
|
||||
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
|
||||
sql db {
|
||||
create table Module
|
||||
}
|
||||
|
||||
mod := Module{
|
||||
name: 'test'
|
||||
@@ -38,7 +40,41 @@ fn main() {
|
||||
select from Module where id == 1
|
||||
}
|
||||
|
||||
println(modul.name)
|
||||
println(modul.creator.name)
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user