diff --git a/examples/hero/db/psql2.vsh b/examples/hero/db/psql2.vsh index ed4b8bf5..94677751 100755 --- a/examples/hero/db/psql2.vsh +++ b/examples/hero/db/psql2.vsh @@ -2,6 +2,10 @@ // #!/usr/bin/env -S v -n -w -enable-globals run import freeflowuniverse.herolib.clients.postgresql_client import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.hero.models.circle +import freeflowuniverse.herolib.core.playcmds +import freeflowuniverse.herolib.hero.db.hero_db + import db.pg // psql -h /tmp -U myuser -d mydb @@ -18,11 +22,8 @@ mut r:=db.exec("select * from users;")! println(r) -// import freeflowuniverse.herolib.core -// import freeflowuniverse.herolib.hero.db.hero_db -// import freeflowuniverse.herolib.hero.models.circle -// import freeflowuniverse.herolib.core.playcmds + // // Configure PostgreSQL client // heroscript := " @@ -51,7 +52,7 @@ postgresql_client.play(mut plbook)! // //Get the configured client -// mut db_client := postgresql_client.get(name: 'test5')! +mut db_client := postgresql_client.get(name: 'aaa')! // println(db_client) diff --git a/lib/biz/bizmodel/play.v b/lib/biz/bizmodel/play.v index 1067a3b4..b89c96eb 100644 --- a/lib/biz/bizmodel/play.v +++ b/lib/biz/bizmodel/play.v @@ -15,7 +15,7 @@ const action_priorities = { pub fn play(mut plbook PlayBook) ! { // group actions by which bizmodel they belong to - actions_by_biz := arrays.group_by[string, &Action](plbook.actions_find(actor: 'bizmodel')!, + actions_by_biz := arrays.group_by[string, &Action](plbook.find(filter: 'bizmodel.')!, fn (a &Action) string { return a.params.get('bizname') or { 'default' } }) @@ -29,7 +29,7 @@ pub fn play(mut plbook PlayBook) ! { } pub fn (mut m BizModel) play(mut plbook PlayBook) ! { - mut actions := plbook.actions_find(actor: 'bizmodel')! + mut actions := plbook.find(filter: 'bizmodel.')! for action in actions.filter(it.name in action_priorities[0]) { m.act(*action)! diff --git a/lib/clients/postgresql_client/postgresql_client_factory_.v b/lib/clients/postgresql_client/postgresql_client_factory_.v index e9d207c3..a4271490 100644 --- a/lib/clients/postgresql_client/postgresql_client_factory_.v +++ b/lib/clients/postgresql_client/postgresql_client_factory_.v @@ -3,7 +3,6 @@ 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 @@ -84,10 +83,8 @@ pub fn play(mut plbook PlayBook) ! { if install_actions.len > 0 { for install_action in install_actions { heroscript := install_action.heroscript() - println(heroscript) - mut obj := encoderhero.decode[PostgresqlClientData](heroscript)! - // mut obj2 := heroscript_loads(heroscript)! - // set(obj2)! + mut obj2 := heroscript_loads(heroscript)! + set(obj2)! } } } diff --git a/lib/clients/postgresql_client/postgresql_client_model.v b/lib/clients/postgresql_client/postgresql_client_model.v index 8a386d3f..23c9cf05 100644 --- a/lib/clients/postgresql_client/postgresql_client_model.v +++ b/lib/clients/postgresql_client/postgresql_client_model.v @@ -23,17 +23,6 @@ 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_ @@ -63,6 +52,8 @@ pub fn heroscript_dumps(obj PostgresqlClient) !string { } pub fn heroscript_loads(heroscript string) !PostgresqlClient { - mut obj := encoderhero.decode[PostgresqlClientData](heroscript)! - return PostgresqlClient{db_:pg.DB{}} + mut obj := encoderhero.decode[PostgresqlClient](heroscript)! + return PostgresqlClient{ + db_: pg.DB{} + } } diff --git a/lib/core/playbook/playbook.v b/lib/core/playbook/playbook.v index e80d2da3..9786ce12 100644 --- a/lib/core/playbook/playbook.v +++ b/lib/core/playbook/playbook.v @@ -128,7 +128,7 @@ pub fn (mut plbook PlayBook) names() ![]string { // // - If actor == "", then matches all actors. // // - If name == "", then matches all actions from the defined actor (if defined). // // - If actiontype == .unknown, then matches all action types; when specified, filters by the action type, default .sal -// pub fn (mut plbook PlayBook) actions_find(args ActionGetArgs) ![]&Action { +// pub fn (mut plbook PlayBook) find(args ActionGetArgs) ![]&Action { // mut res := []&Action{} // for a in plbook.actions { // // If id is specified, return only the action with that id diff --git a/lib/threefold/grid4/cloudslices/play.v b/lib/threefold/grid4/cloudslices/play.v index bc190b0a..cc80ce93 100644 --- a/lib/threefold/grid4/cloudslices/play.v +++ b/lib/threefold/grid4/cloudslices/play.v @@ -4,7 +4,7 @@ import freeflowuniverse.herolib.core.playbook { PlayBook } // this play script should never be called from hero directly its called by gridsimulator pub fn play(mut plbook PlayBook) !map[string]&Node { - mut actions2 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions2 := plbook.find(filter: 'tfgrid_simulator.')! mut nodesdict := map[string]&Node{} for action in actions2 { diff --git a/lib/threefold/grid4/farmingsimulator/play.v b/lib/threefold/grid4/farmingsimulator/play.v index e8190094..5d47cabb 100644 --- a/lib/threefold/grid4/farmingsimulator/play.v +++ b/lib/threefold/grid4/farmingsimulator/play.v @@ -8,7 +8,7 @@ pub fn play(mut plbook PlayBook) ! { // mut sheet_name := '' // first make sure we find a run action to know the name - mut my_actions := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut my_actions := plbook.find(filter: 'tfgridsimulation_farming.')! if my_actions.len == 0 { return @@ -37,7 +37,7 @@ pub fn play(mut plbook PlayBook) ! { } pub fn (mut s Simulator) play(mut plbook PlayBook) ! { - mut actions2 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions2 := plbook.find(filter: 'tfgridsimulation_farming.')! if actions2.len == 0 { // means nothing to do return quickly @@ -93,7 +93,7 @@ pub fn (mut s Simulator) play(mut plbook PlayBook) ! { } // NOW ADD THE REGIONAL INTERNETS - mut actions3 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions3 := plbook.find(filter: 'tfgridsimulation_farming.')! for action_ri in actions3 { if action_ri.name == 'regional_internet_add' { mut iname := action_ri.params.get('name')! @@ -110,7 +110,7 @@ pub fn (mut s Simulator) play(mut plbook PlayBook) ! { } // now do the simulation, run it - mut actions4 := plbook.actions_find(actor: 'tfgridsimulation_farming')! + mut actions4 := plbook.filter(find: 'tfgridsimulation_farming.')! for action_ri in actions4 { if action_ri.name == 'regional_internet_add' { mut iname := action_ri.params.get('name')! diff --git a/lib/threefold/grid4/gridsimulator/play.v b/lib/threefold/grid4/gridsimulator/play.v index 642d22f5..5c90074d 100644 --- a/lib/threefold/grid4/gridsimulator/play.v +++ b/lib/threefold/grid4/gridsimulator/play.v @@ -5,7 +5,7 @@ import freeflowuniverse.herolib.threefold.grid4.cloudslices pub fn play(mut plbook PlayBook) ! { // first make sure we find a run action to know the name - mut my_actions := plbook.actions_find(actor: 'tfgrid_simulator')! + mut my_actions := plbook.find(filter: 'tfgrid_simulator.')! if my_actions.len == 0 { return @@ -33,7 +33,7 @@ pub fn play(mut plbook PlayBook) ! { pub fn (mut self Simulator) play(mut plbook PlayBook) ! { // make sure we know the inca price - mut actions4 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions4 := plbook.find(filter: 'tfgrid_simulator.')! if actions4.len == 0 { return @@ -61,7 +61,7 @@ pub fn (mut self Simulator) play(mut plbook PlayBook) ! { return error("can't find incaprice_define action for tfgrid_simulator, needs to define INCA price.") } - mut actions2 := plbook.actions_find(actor: 'tfgrid_simulator')! + mut actions2 := plbook.find(filter: 'tfgrid_simulator.')! for action in actions2 { if action.name == 'node_growth_define' { mut node_name := action.params.get_default('node_name', '')!