postgresql

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresStore

func NewPostgresStore(URI string) (dbs database.IDatabase, err error)

NewPostgresStore factory method for database

param: URI - represents the database connection string in the format of: postgresql://user:password@host:port/database_name?application_name return: IDatabase instance, error

Types

type PostgresDatabase

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

func (*PostgresDatabase) BulkDelete

func (dbs *PostgresDatabase) BulkDelete(factory EntityFactory, entityIDs []string, keys ...string) (affected int64, err error)

BulkDelete Delete multiple entities from the database in a single transaction (all must be of the same type)

param: factory - Entity factory param: entityIDs - List of entities IDs to delete param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Number of deleted entities, error

func (*PostgresDatabase) BulkInsert

func (dbs *PostgresDatabase) BulkInsert(entities []Entity) (affected int64, err error)

BulkInsert Insert multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to insert return: Number of inserted entities, error

func (*PostgresDatabase) BulkUpdate

func (dbs *PostgresDatabase) BulkUpdate(entities []Entity) (affected int64, err error)

BulkUpdate Update multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to update return: Number of updated entities, error

func (*PostgresDatabase) BulkUpsert

func (dbs *PostgresDatabase) BulkUpsert(entities []Entity) (affected int64, err error)

BulkUpsert Upsert multiple entities to database in a single transaction (all must be of the same type)

param: entities - List of entities to upsert return: Number of updated entities, error

func (*PostgresDatabase) Close

func (dbs *PostgresDatabase) Close() error

Close DB and free resources

func (*PostgresDatabase) Delete

func (dbs *PostgresDatabase) Delete(factory EntityFactory, entityID string, keys ...string) (err error)

Delete entity

param: factory - Entity factory param: entityID - Entity ID to delete param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*PostgresDatabase) DropTable

func (dbs *PostgresDatabase) DropTable(table string) (err error)

DropTable Drop table and indexes

param: table - Table name to drop return: error

func (*PostgresDatabase) ExecuteDDL

func (dbs *PostgresDatabase) ExecuteDDL(ddl map[string][]string) (err error)

ExecuteDDL create table and indexes

param: ddl - The ddl parameter is a map of strings (table names) to array of strings (list of fields to index) return: error

func (*PostgresDatabase) ExecuteSQL

func (dbs *PostgresDatabase) ExecuteSQL(sql string, args ...any) (affected int64, err error)

ExecuteSQL Execute SQL command

param: sql - The SQL command to execute param: args - Statement arguments return: Number of affected records, error

func (*PostgresDatabase) Exists

func (dbs *PostgresDatabase) Exists(factory EntityFactory, entityID string, keys ...string) (result bool, err error)

Exists Check if entity exists by ID

param: factory - Entity factory param: entityID - Entity id param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: bool, error

func (*PostgresDatabase) Get

func (dbs *PostgresDatabase) Get(factory EntityFactory, entityID string, keys ...string) (result Entity, err error)

Get a single entity by ID

param: factory - Entity factory param: entityID - Entity id param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Entity, error

func (*PostgresDatabase) Insert

func (dbs *PostgresDatabase) Insert(entity Entity) (added Entity, err error)

Insert new entity

param: entity - The entity to insert return: Inserted Entity, error

func (*PostgresDatabase) List

func (dbs *PostgresDatabase) List(factory EntityFactory, entityIDs []string, keys ...string) (list []Entity, err error)

List Get list of entities by IDs

param: factory - Entity factory param: entityIDs - List of Entity IDs param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: []Entity, error

func (*PostgresDatabase) Ping

func (dbs *PostgresDatabase) Ping(retries uint, intervalInSeconds uint) error

Ping Test database connectivity

param: retries - how many retries are required (max 10) param: intervalInSeconds - time interval (in seconds) between retries (max 60)

func (*PostgresDatabase) PurgeTable

func (dbs *PostgresDatabase) PurgeTable(table string) (err error)

PurgeTable Fast delete table content (truncate)

param: table - Table name to purge return: error

func (*PostgresDatabase) Query

func (dbs *PostgresDatabase) Query(factory EntityFactory) database.IQuery

Query Helper method to construct query

param: factory - Entity factory return: Query object

func (*PostgresDatabase) SetField

func (dbs *PostgresDatabase) SetField(factory EntityFactory, entityID string, field string, value any, keys ...string) (err error)

SetField Update a single field of the document in a single transaction

param: factory - Entity factory param: entityID - The entity ID to update the field param: field - The field name to update param: value - The field value to update param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*PostgresDatabase) SetFields

func (dbs *PostgresDatabase) SetFields(factory EntityFactory, entityID string, fields map[string]any, keys ...string) (err error)

SetFields Update some fields of the document in a single transaction

param: factory - Entity factory param: entityID - The entity ID to update the field param: fields - A map of field-value pairs to update param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: error

func (*PostgresDatabase) Update

func (dbs *PostgresDatabase) Update(entity Entity) (updated Entity, err error)

Update existing entity

param: entity - The entity to update return: Updated Entity, error

func (*PostgresDatabase) Upsert

func (dbs *PostgresDatabase) Upsert(entity Entity) (updated Entity, err error)

Upsert Update entity or insert it if it does not exist

param: entity - The entity to update return: Updated Entity, error

Jump to

Keyboard shortcuts

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