postgresql

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

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

Connection provides Wire provider for a PostgreSQL database connection

func ConvertSortParameters

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

ConvertSortParameters to sql query string

func ToSnakeCase

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.

Types

type Configuration

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

Configuration repesents database connection configuration

type ConnectionURL

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

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

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

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

type Default

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

Default contains the basic implementation of the SQL interface

func NewCRUDTable

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

NewCRUDTable sets up a new Default struct

func (*Default) Create

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

Create a record

func (*Default) GetDBName

func (d *Default) GetDBName() string

GetDBName returns database's name

func (*Default) GetSession

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

GetSession returns the current session

func (*Default) GetTableName

func (d *Default) GetTableName() string

GetTableName returns table's name

func (*Default) RemoveOne

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

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

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

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

WhereAndFetchOne returns only one element from the given filter

func (*Default) WhereCount

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

WhereCount is used to cound resultset elements from the given filter

Jump to

Keyboard shortcuts

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