postgresdb

package
v0.0.0-...-daa3d23 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

Usage of the Postgres library

Usage of the postgres db init library

  • This library used to initialize the Postgres

  • The inilialization include

    • New DB creation

    • New service user creation

    • Grant all previliges on the DB to the service user

Usage of the Postgres DB migration library

  • This library used to apply the DB schema upgrade, so that main logic can direct use the new tables.

  • This library supports file and BinData based sources to apply the DB schema changes.

Code Layout
  • migration: DB migration specific logic to apply the migration.

  • source: DB schema SQL queries in order of applying with ascending sequential numbers. Examples can be found postgres/test/migrations/postres

  • postgres: Main interface to use by applications to apply the DB schema changes. Refer the test cases for the usage.

Documentation

Overview

Package postgresdb ...

Index

Constants

View Source
const (
	ObjectNotExist       gerrors.ErrorCode = "Object Not Exists"
	DuplicateRecord      gerrors.ErrorCode = "Record already Exist"
	AuthenticationFailed gerrors.ErrorCode = "Authentication Failed"
	PostgresDBError      gerrors.ErrorCode = "Postgres DB Error"
	NoError              gerrors.ErrorCode = "No Error"
)
View Source
const (
	DBConnectError      gerrors.ErrorCode = "Error connecting to the DB"
	GormGetDialectError gerrors.ErrorCode = "Error connecting to the DB"
)

Variables

This section is empty.

Functions

func DataSourceName

func DataSourceName(username string, password string, address string, dbName string, isTLSEnabled bool) string

func NewDB

func NewDB(conf *Config, logger logging.Logger) (*gorm.DB, error)

func NewDBFromENV

func NewDBFromENV(logger logging.Logger) (*gorm.DB, error)

Types

type Config

type Config struct {
	Username     string `envconfig:"PG_DB_SERVICE_USERNAME" required:"true"`
	Password     string `envconfig:"PG_DB_SERVICE_USERPASSWORD" required:"false"`
	DBHost       string `envconfig:"PG_DB_HOST" required:"true"`
	DBPort       string `envconfig:"PG_DB_PORT" required:"true"`
	EntityName   string `envconfig:"PG_DB_ENTITY_NAME" default:"postgres"`
	DatabaseName string `envconfig:"PG_DB_NAME" required:"true"`
	IsTLSEnabled bool   `envconfig:"PG_DB_TLS_ENABLED" default:"false"`
}

type DBClient

type DBClient struct {
	// contains filtered or unexported fields
}

func NewDBClient

func NewDBClient(logger logging.Logger) (store *DBClient, err error)

NewDBClient returns new DB client instance

func (*DBClient) Clear

func (db *DBClient) Clear()

Clear the Rule Table

func (*DBClient) Create

func (db *DBClient) Create(value interface{}) (err error)

Create insert the value into database

func (*DBClient) Delete

func (db *DBClient) Delete(value interface{}, where interface{}) (err error)

Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition Save update value in database, if the value doesn't have primary key, will insert it

func (*DBClient) Find

func (db *DBClient) Find(value interface{}, where interface{}, args ...interface{}) (err error)

Find find records that match given conditions

func (*DBClient) FindFirst

func (db *DBClient) FindFirst(value interface{}, where interface{}, args ...interface{}) (err error)

func (*DBClient) FindWithOrder

func (db *DBClient) FindWithOrder(value interface{}, order string, where interface{}) (err error)

FindWithOrder Find find records that match given conditions with the provided order

func (*DBClient) Save

func (db *DBClient) Save(value interface{}) (err error)

Save update value in database, if the value doesn't have primary key, will insert it

func (*DBClient) Session

func (db *DBClient) Session() *gorm.DB

func (*DBClient) Update

func (db *DBClient) Update(value interface{}, where interface{}) (err error)

Update the value into database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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