2021-02-04 20:28:33 +01:00
|
|
|
import sqlite
|
2021-04-10 16:38:27 +02:00
|
|
|
import mysql
|
2021-02-04 20:28:33 +01:00
|
|
|
|
|
|
|
struct Module {
|
2021-04-10 16:38:27 +02:00
|
|
|
id int [primary; sql: serial]
|
2021-02-04 20:28:33 +01:00
|
|
|
name string
|
2021-04-10 16:38:27 +02:00
|
|
|
nr_downloads int [sql: u64]
|
2021-02-04 20:28:33 +01:00
|
|
|
creator User
|
|
|
|
}
|
|
|
|
|
|
|
|
struct User {
|
2021-04-10 16:38:27 +02:00
|
|
|
id int [primary; sql: serial]
|
2021-02-04 20:28:33 +01:00
|
|
|
age int
|
2021-04-10 16:38:27 +02:00
|
|
|
name string [nonull]
|
2021-02-04 20:28:33 +01:00
|
|
|
is_customer bool
|
|
|
|
skipped_string string [skip]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2021-03-01 00:18:14 +01:00
|
|
|
db := sqlite.connect(':memory:') or { panic(err) }
|
2021-02-04 20:28:33 +01:00
|
|
|
db.exec('drop table if exists User')
|
2021-04-10 16:38:27 +02:00
|
|
|
sql db {
|
|
|
|
create table Module
|
|
|
|
}
|
2021-02-04 20:28:33 +01:00
|
|
|
|
|
|
|
mod := Module{
|
|
|
|
name: 'test'
|
|
|
|
nr_downloads: 10
|
|
|
|
creator: User{
|
|
|
|
age: 21
|
|
|
|
name: 'VUser'
|
|
|
|
is_customer: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql db {
|
|
|
|
insert mod into Module
|
|
|
|
}
|
2021-03-01 00:18:14 +01:00
|
|
|
|
2021-02-04 20:28:33 +01:00
|
|
|
modul := sql db {
|
|
|
|
select from Module where id == 1
|
|
|
|
}
|
|
|
|
|
2021-04-10 16:38:27 +02:00
|
|
|
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
|
|
|
|
}
|
2021-03-01 00:18:14 +01:00
|
|
|
|
2021-04-10 16:38:27 +02:00
|
|
|
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)
|
2021-02-04 20:28:33 +01:00
|
|
|
}
|