This commit is contained in:
2025-07-30 23:00:49 +02:00
parent 932b6508c9
commit 34da4f06e1
4 changed files with 268 additions and 63 deletions

View File

@@ -52,6 +52,7 @@ pub fn set(o PostgresClient) ! {
set_in_mem(o)!
mut context := base.context()!
heroscript := heroscript_dumps(o)!
println(heroscript)
context.hero_config_set('postgresql_client', o.name, heroscript)!
}
@@ -83,7 +84,10 @@ pub fn play(mut plbook PlayBook) ! {
if install_actions.len > 0 {
for install_action in install_actions {
heroscript := install_action.heroscript()
println(heroscript)
mut obj2 := heroscript_loads(heroscript)!
println('postgresql_client playbook action: ${obj2}')
if true{panic("TODO: implement playbook action for postgresql_client, currently not implemented yet.")}
set(obj2)!
}
}

View File

@@ -9,34 +9,9 @@ pub const version = '0.0.0'
const singleton = false
const default = true
pub fn heroscript_default() !string {
heroscript := "
!!postgresql_client.configure
name:'default'
user: 'root'
port: 5432
host: 'localhost'
password: ''
dbname: 'postgres'
"
return heroscript
}
pub fn heroscript_dumps(obj PostgresClient) !string {
return encoderhero.encode[PostgresClient](obj)!
}
pub fn heroscript_loads(heroscript string) !PostgresClient {
mut obj := encoderhero.decode[PostgresClient](heroscript)!
return obj
}
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct PostgresClient {
mut:
db_ ?pg.DB
db_ ?pg.DB @[skip]
pub mut:
name string = 'default'
user string = 'root'
@@ -46,19 +21,6 @@ pub mut:
dbname string = 'postgres'
}
fn cfg_play(p paramsparser.Params) !PostgresClient {
mut mycfg := PostgresClient{
name: p.get_default('name', 'default')!
user: p.get_default('user', 'root')!
port: p.get_int_default('port', 5432)!
host: p.get_default('host', 'localhost')!
password: p.get_default('password', '')!
dbname: p.get_default('dbname', 'postgres')!
}
set(mycfg)!
return mycfg
}
fn obj_init(obj_ PostgresClient) !PostgresClient {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
@@ -80,3 +42,15 @@ pub fn (mut self PostgresClient) db() !pg.DB {
return db
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj PostgresClient) !string {
return encoderhero.encode[PostgresClient](obj)!
}
pub fn heroscript_loads(heroscript string) !PostgresClient {
mut obj := encoderhero.decode[PostgresClient](heroscript)!
return obj
}