...
This commit is contained in:
@@ -4,7 +4,7 @@ import freeflowuniverse.herolib.core.generator.generic as generator
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
mut args := generator.GeneratorArgs{
|
||||
path: '~/code/github/freeflowuniverse/herolib/lib/installers/infra'
|
||||
path: '~/code/github/freeflowuniverse/herolib/lib/clients/postgresql_client'
|
||||
force: true
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.clients.postgresql_client
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.hero.db.hero_db
|
||||
import freeflowuniverse.herolib.hero.models.circle
|
||||
// import freeflowuniverse.herolib.core.playcmds
|
||||
|
||||
// Configure PostgreSQL client
|
||||
heroscript := "
|
||||
!!postgresql_client.configure password: 'testpass'
|
||||
name:'test2'
|
||||
!!postgresql_client.configure
|
||||
password:'testpass'
|
||||
name:'test5'
|
||||
user: 'testuser'
|
||||
port: 5432
|
||||
host: 'localhost'
|
||||
@@ -18,28 +21,62 @@ mut plbook := playbook.new(text: heroscript)!
|
||||
postgresql_client.play(mut plbook)!
|
||||
|
||||
// Get the configured client
|
||||
mut db_client := postgresql_client.get(name: 'test2')!
|
||||
mut db_client := postgresql_client.get(name: 'test5')!
|
||||
|
||||
// println(db_client)
|
||||
|
||||
// // Check if test database exists, create if not
|
||||
// if !db_client.db_exists('test')! {
|
||||
// println('Creating database test...')
|
||||
// db_client.db_create('test')!
|
||||
// }
|
||||
// Check if test database exists, create if not
|
||||
if !db_client.db_exists('test')! {
|
||||
println('Creating database test...')
|
||||
db_client.db_create('test')!
|
||||
}
|
||||
|
||||
// // Switch to test database
|
||||
// db_client.dbname = 'test'
|
||||
// Switch to test database
|
||||
db_client.dbname = 'test'
|
||||
|
||||
// // Create table if not exists
|
||||
// create_table_sql := 'CREATE TABLE IF NOT EXISTS users (
|
||||
// id SERIAL PRIMARY KEY,
|
||||
// name VARCHAR(100) NOT NULL,
|
||||
// email VARCHAR(255) UNIQUE NOT NULL,
|
||||
// created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
// )'
|
||||
// Create table if not exists
|
||||
create_table_sql := 'CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)'
|
||||
|
||||
// println('Creating table users if not exists...')
|
||||
// db_client.exec(create_table_sql)!
|
||||
println('Creating table users if not exists...')
|
||||
db_client.exec(create_table_sql)!
|
||||
|
||||
// println('Database and table setup completed successfully!')
|
||||
println('Database and table setup completed successfully!')
|
||||
|
||||
|
||||
// Create HeroDB for Circle type
|
||||
mut circle_db := hero_db.new[circle.Circle](db_client)
|
||||
|
||||
println(circle_db)
|
||||
|
||||
if true{panic("sd")}
|
||||
|
||||
circle_db.ensure_table()!
|
||||
|
||||
// Create and save a circle
|
||||
mut my_circle := circle.Circle{
|
||||
name: "Tech Community"
|
||||
description: "A community for tech enthusiasts"
|
||||
domain: "tech.example.com"
|
||||
config: circle.CircleConfig{
|
||||
max_members: 1000
|
||||
allow_guests: true
|
||||
auto_approve: false
|
||||
theme: "modern"
|
||||
}
|
||||
status: circle.CircleStatus.active
|
||||
}
|
||||
|
||||
circle_db.save(&my_circle)!
|
||||
|
||||
// Retrieve the circle
|
||||
retrieved_circle := circle_db.get_by_index({
|
||||
"domain": "tech.example.com"
|
||||
})!
|
||||
|
||||
// Search circles by status
|
||||
active_circles := circle_db.search_by_index("status", "active")!
|
||||
Reference in New Issue
Block a user