...
This commit is contained in:
@@ -3,6 +3,7 @@ module postgresql_client
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
|
||||
__global (
|
||||
postgresql_client_global map[string]&PostgresqlClient
|
||||
@@ -83,8 +84,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
println(heroscript)
|
||||
mut obj := encoderhero.decode[PostgresqlClientData](heroscript)!
|
||||
// mut obj2 := heroscript_loads(heroscript)!
|
||||
// set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ module postgresql_client
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import os
|
||||
import db.pg
|
||||
|
||||
@@ -9,6 +10,7 @@ pub const version = '0.0.0'
|
||||
const singleton = false
|
||||
const default = true
|
||||
|
||||
@[heap]
|
||||
pub struct PostgresqlClient {
|
||||
mut:
|
||||
db_ ?pg.DB @[skip]
|
||||
@@ -21,6 +23,17 @@ pub mut:
|
||||
dbname string = 'postgres'
|
||||
}
|
||||
|
||||
pub struct PostgresqlClientData {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
user string = 'root'
|
||||
port int = 5432
|
||||
host string = 'localhost'
|
||||
password string = ''
|
||||
dbname string = 'postgres'
|
||||
}
|
||||
|
||||
|
||||
fn obj_init(obj_ PostgresqlClient) !PostgresqlClient {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
@@ -28,7 +41,7 @@ fn obj_init(obj_ PostgresqlClient) !PostgresqlClient {
|
||||
}
|
||||
|
||||
pub fn (mut self PostgresqlClient) db() !pg.DB {
|
||||
// console.print_debug(args)
|
||||
console.print_debug(self)
|
||||
mut db := self.db_ or {
|
||||
mut db_ := pg.connect(
|
||||
host: self.host
|
||||
@@ -50,6 +63,6 @@ pub fn heroscript_dumps(obj PostgresqlClient) !string {
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !PostgresqlClient {
|
||||
mut obj := encoderhero.decode[PostgresqlClient](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[PostgresqlClientData](heroscript)!
|
||||
return PostgresqlClient{db_:pg.DB{}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user