pkg: zntr.io/pkg/db/adapter/postgresql Index | Files

package postgresql

import "zntr.io/pkg/db/adapter/postgresql"

Index

Package Files

connection.go default_crud.go helpers.go qs.go

func Connection Uses

func Connection(ctx context.Context, cfg *Configuration) (*sqlx.DB, error)

Connection provides Wire provider for a PostgreSQL database connection

func ConvertSortParameters Uses

func ConvertSortParameters(params db.SortParameters, sortableColumns map[string]bool) []string

ConvertSortParameters to sql query string

func ToSnakeCase Uses

func ToSnakeCase(in string) string

ToSnakeCase convert the given string to snake case following the Golang format: acronyms are converted to lower-case and preceded by an underscore.

type Configuration Uses

type Configuration struct {
    AutoMigrate      bool
    ConnectionString string
    Username         string
    Password         string
}

Configuration represents database connection configuration

type ConnectionURL Uses

type ConnectionURL struct {
    User     string
    Password string
    Host     string
    Socket   string
    Database string
    Options  map[string]string
}

ConnectionURL represents a parsed PostgreSQL connection URL.

You can use a ConnectionURL struct as an argument for Open:

var settings = postgresql.ConnectionURL{
  Host:       "localhost",          // PostgreSQL server IP or name.
  Database:   "peanuts",            // Database name.
  User:       "cbrown",             // Optional user name.
  Password:   "snoopy",             // Optional user password.
}

sess, err = postgresql.Open(settings)

If you already have a valid DSN, you can use ParseURL to convert it into a ConnectionURL before passing it to Open.

func ParseURL Uses

func ParseURL(s string) (u ConnectionURL, err error)

ParseURL parses the given DSN into a ConnectionURL struct. A typical PostgreSQL connection URL looks like:

postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full

func (ConnectionURL) String Uses

func (c ConnectionURL) String() (s string)

String reassembles the parsed PostgreSQL connection URL into a valid DSN.

type Default Uses

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

Default contains the basic implementation of the SQL interface

func NewCRUDTable Uses

func NewCRUDTable(session *sqlx.DB, db, table string, columns, sortable []string) *Default

NewCRUDTable sets up a new Default struct

func (*Default) Create Uses

func (d *Default) Create(ctx context.Context, data interface{}) error

Create a record

func (*Default) GetDBName Uses

func (d *Default) GetDBName() string

GetDBName returns database's name

func (*Default) GetSession Uses

func (d *Default) GetSession() interface{}

GetSession returns the current session

func (*Default) GetTableName Uses

func (d *Default) GetTableName() string

GetTableName returns table's name

func (*Default) RemoveOne Uses

func (d *Default) RemoveOne(ctx context.Context, filter interface{}) error

RemoveOne is used to remove one element from the collection that match the filter

func (*Default) Search Uses

func (d *Default) Search(ctx context.Context, filter interface{}, pagination *db.Pagination, sortParams *db.SortParameters, results interface{}) (int, error)

Search for element in collection

func (*Default) Update Uses

func (d *Default) Update(ctx context.Context, updates map[string]interface{}, filter interface{}) error

Update the collection element with updates set matching the given filter

func (*Default) WhereAndFetchOne Uses

func (d *Default) WhereAndFetchOne(ctx context.Context, filter interface{}, result interface{}) error

WhereAndFetchOne returns only one element from the given filter

func (*Default) WhereCount Uses

func (d *Default) WhereCount(ctx context.Context, filter interface{}) (int, error)

WhereCount is used to cound resultset elements from the given filter

Package postgresql imports 19 packages (graph). Updated 2020-06-17. Refresh now. Tools for package owners.