postgresql

package
v1.2.107 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresDatabase added in v1.2.5

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

NewPostgresDatabase 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

func NewPostgresDatabaseWithMessageBus added in v1.2.31

func NewPostgresDatabaseWithMessageBus(URI string, bus messaging.IMessageBus) (dbs database.IDatabase, err error)

NewPostgresDatabaseWithMessageBus factory method for database with injected message bus param: URI - represents the database connection string in the format of: postgresql://user:password@host:port/database_name?application_name return: IDatabase instance, error

func NewPostgresStore

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

NewPostgresStore factory method for datastore 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 NotificationHandler added in v1.2.99

type NotificationHandler func(np NotificationPayload)

type NotificationPayload added in v1.2.99

type NotificationPayload struct {
	Operation string        `json:"operation"`
	ID        string        `json:"id"`
	Entity    entity.Entity `json:"data"`
}

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) BulkSetFields added in v1.2.34

func (dbs *PostgresDatabase) BulkSetFields(factory EntityFactory, field string, values map[string]any, keys ...string) (affected int64, error error)

BulkSetFields Update specific field of multiple entities in a single transaction (eliminates the need to fetch - change - update)

param: factory - Entity factory param: field - The field name to update param: values - The map of entity Id to field value param: keys - Sharding key(s) (for sharded entities and multi-tenant support) return: Number of updated 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) CloneDatabase added in v1.2.41

func (dbs *PostgresDatabase) CloneDatabase() (database.IDatabase, error)

CloneDatabase Returns a clone (copy) of the database instance

func (*PostgresDatabase) CloneDatastore added in v1.2.41

func (dbs *PostgresDatabase) CloneDatastore() (database.IDatastore, error)

CloneDatastore Returns a clone (copy) of the database instance

func (*PostgresDatabase) Close

func (dbs *PostgresDatabase) Close() error

Close DB and free resources

func (*PostgresDatabase) CreateEntityIndex added in v1.2.5

func (dbs *PostgresDatabase) CreateEntityIndex(factory EntityFactory, key string) (name string, err error)

CreateEntityIndex creates an index of entity and add entity field mapping

func (*PostgresDatabase) CreateIndex added in v1.2.5

func (dbs *PostgresDatabase) CreateIndex(indexName string) (name string, err error)

CreateIndex creates an index (without mapping)

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) DropIndex added in v1.2.5

func (dbs *PostgresDatabase) DropIndex(indexName string) (ack bool, err error)

DropIndex drops an index

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) ExecuteQuery added in v1.2.42

func (dbs *PostgresDatabase) ExecuteQuery(source string, sql string, args ...any) ([]Json, error)

ExecuteQuery Execute native SQL query

func (*PostgresDatabase) ExecuteSQL

func (dbs *PostgresDatabase) ExecuteSQL(sql string, args ...any) (int64, 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) IndexExists added in v1.2.5

func (dbs *PostgresDatabase) IndexExists(indexName string) (exists bool)

IndexExists tests if index exists

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) ListIndices added in v1.2.50

func (dbs *PostgresDatabase) ListIndices(pattern string) (map[string]int, error)

ListIndices returns a list of all indices matching the pattern

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) Subscribe added in v1.2.99

func (dbs *PostgresDatabase) Subscribe(ef entity.EntityFactory, handler NotificationHandler) error

Subscribe subscribes to a specified PostgreSQL channel to receive notifications and ensures the trigger and notify function are created in the database.

Parameters:

  • channel: The name of the PostgreSQL channel to listen for notifications.
  • handler: A callback function of type `NotificationHandler` that processes the notification payload.

Return Value:

  • error: Returns an error if there is a failure in setting up the trigger, subscribing to the channel, or receiving notifications.

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