Skip to content

clients.postgres #

postgres client

use hero to work with postgres


Usage: hero postgres [flags] [commands]

manage postgresql

Flags:
  -help               Prints help information.
  -man                Prints the auto-generated manpage.

Commands:
  exec                execute a query
  check               check the postgresql connection
  configure           configure a postgresl connection.
  backup              backup
  print               print configure info.
  list                list databases

configure

the postgres configuration is stored on the filesystem for further use, can be configured as follows

import freeflowuniverse.crystallib.clients.postgres

postgres.configure(name:'default',
    user :'root'
    port : 5432
    host  : 'localhost'
    password : 'ssss'
    dbname :'postgres')!

mut db:=postgres.get(name:'default')!

configure through heroscript

import freeflowuniverse.crystallib.clients.postgres

heroscript:='
!!postgresclient.define name:'default'
    //TO IMPLEMENT
'


postgres.configure(heroscript:heroscript)!


//can also be done through get directly
mut cl:=postgres.get(reset:true,name:'default',heroscript:heroscript)

some postgresql cmds

import freeflowuniverse.crystallib.clients.postgres

mut cl:=postgres.get()! //will default get postgres client with name 'default'

cl.db_exists('mydb')!

use the good module of v

fn config #

fn config(args Config) Config

return a config object even if from partial info

fn configurator #

fn configurator(instance string, mut context play.Context) !play.Configurator[Config]

get the configurator

fn configure_interactive #

fn configure_interactive(mut args Config, mut session base.Session) !

fn get #

fn get(clientargs ClientArgs) !PostgresClient

fn play_session #

fn play_session(mut session base.Session) !

struct BackupParams #

@[params]
struct BackupParams {
pub mut:
	dbname string
	dest   string
}

struct ClientArgs #

@[params]
struct ClientArgs {
pub mut:
	instance string @[required]
	playargs ?play.PlayArgs
}

struct Config #

@[params]
struct Config {
pub mut:
	instance   string = 'default'
	user       string = 'root'
	port       int    = 5432
	host       string = 'localhost'
	password   string
	dbname     string = 'postgres'
	heroscript string
	reset      bool
}

struct PostgresClient #

struct PostgresClient {
	play.BaseConfig
pub mut:
	config Config
	db     pg.DB
}

fn (PostgresClient) backup #

fn (mut self PostgresClient) backup(args BackupParams) !

fn (PostgresClient) check #

fn (mut self PostgresClient) check() !

fn (PostgresClient) db_create #

fn (mut self PostgresClient) db_create(name_ string) !

fn (PostgresClient) db_delete #

fn (mut self PostgresClient) db_delete(name_ string) !

fn (PostgresClient) db_exists #

fn (mut self PostgresClient) db_exists(name_ string) !bool

fn (PostgresClient) db_names #

fn (mut self PostgresClient) db_names() ![]string

fn (PostgresClient) exec #

fn (mut self PostgresClient) exec(c_ string) ![]pg.Row