004
This commit is contained in:
8
src/databases/config_databases_sqlite.v
Normal file
8
src/databases/config_databases_sqlite.v
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module databases
|
||||||
|
|
||||||
|
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
||||||
|
|
||||||
|
pub fn create_db_connection() !sqlite.DB {
|
||||||
|
mut db := sqlite.connect('app.db')!
|
||||||
|
return db
|
||||||
|
}
|
10
src/main.v
10
src/main.v
@@ -1,6 +1,7 @@
|
|||||||
module main
|
module main
|
||||||
|
|
||||||
import veb
|
import veb
|
||||||
|
import databases
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
veb.Context
|
veb.Context
|
||||||
@@ -15,6 +16,15 @@ pub fn (app &App) index(mut ctx Context) veb.Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
mut db := databases.create_db_connection() or { panic(err) }
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
create table User
|
||||||
|
create table Plane
|
||||||
|
create table Ticket
|
||||||
|
} or { panic('error on create table: ${err}') }
|
||||||
|
|
||||||
|
db.close() or { panic(err) }
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
|
|
||||||
app.handle_static('static', false)!
|
app.handle_static('static', false)!
|
||||||
|
@@ -4,11 +4,13 @@ module main
|
|||||||
pub struct Plane {
|
pub struct Plane {
|
||||||
mut:
|
mut:
|
||||||
id int @[primary; sql: serial]
|
id int @[primary; sql: serial]
|
||||||
from string @[nonull; sql_type: 'TEXT']
|
from string @[sql_type: 'TEXT']
|
||||||
to string @[nonull; sql_type: 'TEXT']
|
to string @[sql_type: 'TEXT']
|
||||||
seats string @[nonull; sql_type: 'TEXT']
|
seats string @[sql_type: 'TEXT']
|
||||||
seats_available int @[nonull; sql_type: 'INT']
|
seats_available int @[sql_type: 'INT']
|
||||||
time string @[nonull; sql_type: 'TEXT']
|
time string @[sql_type: 'TEXT']
|
||||||
status string @[nonull; sql_type: 'TEXT']
|
date string @[sql_type: 'TEXT']
|
||||||
tickets []Ticket @[foreign_key: 'plane_id'; on_delete: 'cascade'; on_update: 'cascade']
|
price int @[sql_type: 'INT']
|
||||||
|
status string @[sql_type: 'TEXT']
|
||||||
|
tickets []Ticket @[fkey: 'plane_id']
|
||||||
}
|
}
|
||||||
|
@@ -6,4 +6,5 @@ mut:
|
|||||||
id int @[primary; sql: serial]
|
id int @[primary; sql: serial]
|
||||||
user_id int
|
user_id int
|
||||||
plane_id int
|
plane_id int
|
||||||
|
status string @[sql_type: 'TEXT']
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ module main
|
|||||||
pub struct User {
|
pub struct User {
|
||||||
mut:
|
mut:
|
||||||
id int @[primary; sql: serial]
|
id int @[primary; sql: serial]
|
||||||
username string @[nonull; sql_type: 'TEXT'; unique]
|
username string @[sql_type: 'TEXT'; unique]
|
||||||
password string @[nonull; sql_type: 'TEXT']
|
password string @[sql_type: 'TEXT']
|
||||||
tickets []Ticket @[foreign_key: 'user_id']
|
tickets []Ticket @[fkey: 'user_id']
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user