gosl

package module
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 9 Imported by: 4

README

gosl


gosl is a library that provides common golang's sql builder.
This README is still not fully completed yet, will be updated shortly. The codes were created by @johnjerrico, published here so it can be used publicly.

Installation

Get the code with:

$ go get github.com/louvri/gosl
Usage

On your request model add the transformer if you want:

type Request struct {
	...
	Transformer *transformer.Transformer
}

Then put it at your request object creation/modification:

...
    Object: search.Request{
        ...,
        Transformer: &transformer.Transformer{
            Store: func(data interface{}) error {
                return request.Transformer.Store(data)
            },
            Transform: func(data interface{}) (interface{}, error) {
                tmp := data.(dbModel.Model)
                tmp.Status = constant.StatusMap[tmp.Status]
                transformedSales, _ := request.Transformer.Transform(tmp)
                return transformedSales, nil
            },
        },
    }
...

And call it within the sql retrieval codes:

    ...
    for rows.Next() {
        ...
        _, err = obj.Transform(result)
        if err != nil {
            return err
        }
        ...
    }
    ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToDB

func ConnectToDB(user, password, host, port, name string, maxOpen, maxIdle int, maxLifetime, maxIdleLifetime time.Duration) *sqlx.DB

ConnectToDB simple wrapper for db connection with sqlx

func RunInTransaction

func RunInTransaction(ctx context.Context, fn func(ctx context.Context) error) error

RunInTransaction db wrapper for transaction

Types

type Gosl_Key added in v0.0.19

type Gosl_Key int
const CACHE_SQL_KEY Gosl_Key = 1988
const SQL_KEY Gosl_Key = 1977
const SYSTEM_STACK Gosl_Key = 101

type Key

type Key int
var STACK Key = 101

type Kit added in v0.0.19

type Kit interface {
	RunInTransaction(ctx context.Context, handler func(ctx context.Context) error) error
	ContextSwitch(ctx context.Context, key interface{}) context.Context
	ContextReset(ctx context.Context) context.Context
}

func New added in v0.0.19

func New(ctx context.Context) Kit

type Queryable

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

func NewQueryable

func NewQueryable(db interface{}) *Queryable

func (*Queryable) BindNamed

func (qtx *Queryable) BindNamed(query string, arg interface{}) (string, []interface{}, error)

BindNamed ...

func (*Queryable) DB

func (qtx *Queryable) DB() *sqlx.DB

DB return db

func (*Queryable) DriverName

func (qtx *Queryable) DriverName() string

DriverName ...

func (*Queryable) Exec

func (qtx *Queryable) Exec(query string, args ...interface{}) (_sql.Result, error)

Exec ...

func (*Queryable) ExecContext

func (qtx *Queryable) ExecContext(ctx context.Context, query string, args ...interface{}) (_sql.Result, error)

ExecContext ...

func (*Queryable) Get

func (qtx *Queryable) Get(dest interface{}, query string, args ...interface{}) error

Get ...

func (*Queryable) GetContext

func (qtx *Queryable) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetContext ...

func (*Queryable) Key

func (qtx *Queryable) Key() interface{}

func (*Queryable) MustExec

func (qtx *Queryable) MustExec(query string, args ...interface{}) _sql.Result

MustExec ...

func (*Queryable) MustExecContext

func (qtx *Queryable) MustExecContext(ctx context.Context, query string, args ...interface{}) _sql.Result

MustExecContext ...

func (*Queryable) NamedExec

func (qtx *Queryable) NamedExec(query string, arg interface{}) (_sql.Result, error)

NamedExec ...

func (*Queryable) NamedExecContext

func (qtx *Queryable) NamedExecContext(ctx context.Context, query string, arg interface{}) (_sql.Result, error)

NamedExecContext ...

func (*Queryable) NamedQuery

func (qtx *Queryable) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)

NamedQuery ...

func (*Queryable) NamedQueryRowx

func (qtx *Queryable) NamedQueryRowx(query string, args interface{}) (*sqlx.Row, error)

NamedQueryRowx run BindNamed then QueryRowx

func (*Queryable) NamedQueryRowxContext

func (qtx *Queryable) NamedQueryRowxContext(ctx context.Context, query string, args interface{}) (*sqlx.Row, error)

NamedQueryRowxContext run BindNamed then QueryRowxContext

func (*Queryable) PrepareNamed

func (qtx *Queryable) PrepareNamed(query string) (*sqlx.NamedStmt, error)

PrepareNamed ...

func (*Queryable) PrepareNamedContext

func (qtx *Queryable) PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)

PrepareNamedContext ...

func (*Queryable) Preparex

func (qtx *Queryable) Preparex(query string) (*sqlx.Stmt, error)

Preparex ...

func (*Queryable) PreparexContext

func (qtx *Queryable) PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)

PreparexContext ...

func (*Queryable) QueryRowx

func (qtx *Queryable) QueryRowx(query string, args ...interface{}) *sqlx.Row

QueryRowx ...

func (*Queryable) QueryRowxContext

func (qtx *Queryable) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

QueryRowxContext ...

func (*Queryable) Queryx

func (qtx *Queryable) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

Queryx ...

func (*Queryable) QueryxContext

func (qtx *Queryable) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)

QueryxContext ...

func (*Queryable) Rebind

func (qtx *Queryable) Rebind(query string) string

Rebind ...

func (*Queryable) Select

func (qtx *Queryable) Select(dest interface{}, query string, args ...interface{}) error

Select ...

func (*Queryable) SelectContext

func (qtx *Queryable) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

SelectContext ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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