goalPostgreSQL

package module
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 8 Imported by: 0

README

goalPostgreSQL

Go PostgreSQL Library. This module library use PostgreSQL driver from jackc/pgx.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PgClose

func PgClose(connectionPool *pgxpool.Pool)

Close PostgreSQL connection

func PgDelete added in v0.1.19

func PgDelete(connectionPool *pgxpool.Pool, table string, columns []string, inputParameters ...any) (int64, error)

Delete data to PostgreSQL table. On success delete this method will return how many rows data deleted. Please put your insert query arguments in inputParameters to prevent SQL Injection. Arguments should be referenced positionally from the SQL string as $1, $2 and etc.

Function use example: pgDelete(connectionPool, "database.public.users", []string{"my_column1", "my_column2", "my_column3"}, "value of column1", "value of column2", "value of column3")

func PgInsert added in v0.1.10

func PgInsert(connectionPool *pgxpool.Pool, table string, columns []string, columnPrimaryKey string, inputParameters ...any) (int64, error)

Insert data to PostgreSQL table. On success insert this method will return data inserted primary key. Please put your insert query arguments in inputParameters to prevent SQL Injection. Arguments should be referenced positionally from the SQL string as $1, $2 and etc.

Function use example: goalPostgreSQL.PgInsertOne(connectionPool, "database.public.users", []string{"my_column1", "my_column2", "my_column3"}, "my_id_column_primary_key", "value of column1", "value of column2", "value of column3")

func PgPoolConnect

func PgPoolConnect(databaseURL string) (*pgxpool.Pool, pgtype.Text, error)

Init postgres connection.

func PgSelect

func PgSelect(connectionPool *pgxpool.Pool, columns []string, table string,
	condition string, inputParameters ...any) ([]map[string]interface{}, error)

PostgreSQL select query for multiple rows of data. Please put your select query arguments in inputParameters to prevent SQL Injection. Arguments should be referenced positionally from the SQL string as $1, $2, etc.

Function use example: goalPostgreSQL.PgSelect(connectionPool, []string{"id"}, "database.public.users", "WHERE username = $1 AND password = $2", username, password)

func PgUpdate added in v0.1.7

func PgUpdate(connectionPool *pgxpool.Pool, table string, columns []string, condition string, inputParameters ...any) (int64, error)

Update PostgreSQL table. On success update this method will return how many rows updated. Please put your update query arguments in inputParameters to prevent SQL Injection. Arguments should be referenced positionally from the SQL string as $1, $2 and etc. Inserted arguments reference in condition parameter must be count after the last columns.

Example: There is 7 columns will be update, so the arguments reference in condition parameter should start from $8.

Function use example: goalPostgreSQL.PgUpdate(connectionPool, "database.public.users", []string{column1, column2, column3}, "WHERE id = $4", valueColumn1, valueColumn2, valueColumn3)

Function use with PostgreSQL append function: goalPostgreSQL.PgUpdate(connectionPool, "database.public.users", []string{column1.append, column2.append, column3.append}, "WHERE id = $4", valueColumn1, valueColumn2, valueColumn3)

Types

This section is empty.

Jump to

Keyboard shortcuts

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