Documentation ¶
Index ¶
- func Connection(ctx context.Context, cfg *Configuration) (*sqlx.DB, error)
- func ConvertSortParameters(params db.SortParameters, sortableColumns map[string]bool) []string
- func ToSnakeCase(in string) string
- type Configuration
- type ConnectionURL
- type Default
- func (d *Default) Create(ctx context.Context, data interface{}) error
- func (d *Default) GetDBName() string
- func (d *Default) GetSession() interface{}
- func (d *Default) GetTableName() string
- func (d *Default) RemoveOne(ctx context.Context, filter interface{}) error
- func (d *Default) Search(ctx context.Context, filter interface{}, pagination *db.Pagination, ...) (int, error)
- func (d *Default) Update(ctx context.Context, updates map[string]interface{}, filter interface{}) error
- func (d *Default) WhereAndFetchOne(ctx context.Context, filter interface{}, result interface{}) error
- func (d *Default) WhereCount(ctx context.Context, filter interface{}) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connection ¶
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 ¶
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 ¶
NewCRUDTable sets up a new Default struct
func (*Default) GetSession ¶
func (d *Default) GetSession() interface{}
GetSession returns the current session
func (*Default) GetTableName ¶
GetTableName returns table's name
func (*Default) RemoveOne ¶
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