postgresql

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

This package is wrapper for postgresql db connections. To use it with your own structs, you have to add an column-tag to your structs and an ID field.

This package is currently in a BETA-state.

This package is wrapper for postgresql db connections. To use it with your own structs, you have to add an column-tag to your structs and an ID field.

This package is currently in a BETA-state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Postgres

type Postgres struct {
	Connection PostgresConnection `json:"connection"`
	// contains filtered or unexported fields
}

sqlite3 struct to group informations, json ready

func (*Postgres) CheckConnection

func (psql *Postgres) CheckConnection() error

check connection to dbfile

func (*Postgres) Connect

func (psql *Postgres) Connect(pc PostgresConnection)

connect to the sqlite database file

func (Postgres) DB

func (psql Postgres) DB() *sql.DB

get the db pointer from the sqlite3 pkg

func (Postgres) DeleteObject

func (psql Postgres) DeleteObject(tblName string, obj interface{}) (err error)

this function generates an "delete" statement, where the given struct is used to delete the object from the given table. The function requires the object struct to have an "ID" field with a valid value.

Parameters:

  • `tblName` : string > the name of the table, where tho object is estimated
  • `obj` : interface{} | struct > the object with an ID-field and an valid value

func (Postgres) Disconnect

func (psql Postgres) Disconnect() error

disconnect from the currently connected file

func (Postgres) InsertObject

func (psql Postgres) InsertObject(tblName string, objPointer, obj interface{}) (err error)

this function generates an "insert" statement, where the given struct is inserted into the given table. The function requires the object struct to have an "ID" field, so the struct receives the new id.

Parameters:

  • `tblName` : string > the name of the table, where tho object is estimated
  • `objPointer` : interface{} | *struct > pointer to the object, is used to get the struct-informations
  • `obj` : interface{} | struct > the same object, but not as a pointer, is used to get the struct-informations

func (Postgres) SelectObject

func (psql Postgres) SelectObject(tblName string, objPointer, obj interface{}) (err error)

this function generates a "select" statement, where the estimated object is exactly one object, not from a list. The function requires the object- struct to have an "ID" field.

Parameters:

  • `tblName` : string > the name of the table, where tho object is estimated
  • `objPointer` : interface{} | *struct > pointer to the object, is used to get the struct-informations
  • `obj` : interface{} | struct > the same object, but not as a pointer, where the data should be stored

func (Postgres) SelectObjects

func (psql Postgres) SelectObjects(tblName string, objPointer interface{}) (err error)

this function generates a "select" statement, where the estimated object is a list of objects. The function does not require the object struct to have an "ID" field.

Parameters:

  • `tblName` : string > the name of the table, where tho object is estimated
  • `objPointer` : interface{} | *[]struct > contains the list of the array

func (Postgres) SpecificSelectObject

func (psql Postgres) SpecificSelectObject(sqlStatement string, objPointer interface{}) (err error)

this function uses a specified sql-statement to select multiple objects. the statement will be given through the variable sqlStatement <string>

Parameters:

  • `sqlStatement` : string > the sql stateent, which is used to receive the objects
  • `objPointer` : interface{} | *struct > contains the pointer to the object -> *[]struct

func (Postgres) SpecificSelectObjects

func (psql Postgres) SpecificSelectObjects(sqlStatement string, objPointer interface{}) (err error)

this function uses a specified sql-statement to select multiple objects. the statement will be given through the variable sqlStatement <string>

Parameters:

  • `sqlStatement` : string > the sql stateent, which is used to receive the objects
  • `objPointer` : interface{} | *[]struct > contains the list of the objects

func (Postgres) UpdateObject

func (psql Postgres) UpdateObject(tblName string, objPointer, obj interface{}) (err error)

this function generates an "update" statement, where the given struct updates the values in the given table. The function requires the object struct to have an "ID" field, so the table receives the new values.

Parameters:

  • `tblName` : string > the name of the table, where tho object is estimated
  • `objPointer` : interface{} | *struct > pointer to the object, is used to store the values
  • `obj` : interface{} | struct > the same object, but not as a pointer, is used to get the struct-informations

type PostgresConnection

type PostgresConnection struct {
	Host         string `json:"host"`
	Port         string `json:"port"`
	User         string `json:"user"`
	Password     string `json:"password"`
	DatabaseName string `json:"dbname"`
	SSLMode      string `json:"sslode"`
}

postgres connectionstring object, json ready, no encryption

func (PostgresConnection) ConnectionString

func (pc PostgresConnection) ConnectionString() string

receive the connectionstring of a PostgresConnection object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL