dialects

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Actions is all helper functions that are called within the dialects

Index

Constants

View Source
const DIALECT_TYPE_MYSQL = "mysql"
View Source
const DIALECT_TYPE_PSQL = "psql"
View Source
const DIALECT_TYPE_SQLITE = "sqlite3"

Variables

View Source
var Databases map[string]DialectHandler

Functions

func BulkDelete added in v1.0.1

func BulkDelete(db *sql.DB, model any, dialectType string) error

To delete results in bulk, pass in a slice. This will batch delete records for the given Model

func Create

func Create(db *sql.DB, model any, dialectType string) error

func Delete

func Delete(db *sql.DB, model any, dialectType string) error

No id is present within the model and no args are passed, the FIRST recored (using limit 1) from the given model will be deleted To delete records with values other than ID, you can insert a model without an ID, but with other fields present. i.e. to delete a user by name: Delete(&User{name: "carl"}) Without an ID field, but with name present, only "carl" will be deleted Multiple attributes will be treated as &'s

func Find

func Find(db *sql.DB, model any, dialectType string, args ...any) error

Will accept arbitrary arguments, though only 1 is used, which should be the ID of the object to find. If an ID is not passed, ALL objects of the model will be returned If there is no id and the passed model is not a slice, the first row is returned for the given model If an ID IS passed, only a single object should ever be found. If an ID is passed, the the model is converted into a slice of model type

func Update

func Update(db *sql.DB, model any, dialectType string) error

func Where

func Where(db *sql.DB, model any, stmt string, limit int, dialectType string, args ...any) error

Will return all rows found unless <= 1 rows are present in result of query Will accept a limit, limit of <= 0 will return all rows found matching the query Where is an all in 1 method with no chaining. Pass in the model, statement, desired limit (if there is one, else pass in <= 0), and any arguments to satiate the query

Types

type DBConfig

type DBConfig struct {
	Port        int           `yaml:"port,omitempty"`
	Host        string        `yaml:"host,omitempty"`
	Pool        int           `yaml:"pool,omitempty"`
	Connect     bool          `yaml:"connect,omitempty"`
	Password    string        `yaml:"password,omitempty"`
	User        string        `yaml:"user,omitempty"`
	Database    string        `yaml:"database,omitempty"`
	Path        string        `yaml:"path,omitempty"`
	Dialect     string        `yaml:"dialect"`
	Auth        bool          `yaml:"auth"`
	MaxIdleTime time.Duration `yaml:"maxIdleTime,omitempty"`
	MaxLifetime time.Duration `yaml:"maxLifetime,omitempty"`
	MaxIdleConn int           `yaml:"maxIdleConn,omitempty"`
	MaxOpenConn int           `yaml:"maxOpenConn,omitempty"`
}

type DialectHandler

type DialectHandler interface {
	Create(model any) error
	Update(model any) error
	Delete(model any) error
	BulkDelete(model any) error
	Where(model any, stmt string, limit int, args ...any) error
	Find(model any, args ...any) error
	Raw(query string, args ...any) (*RawQuery, error)
	SetDB(connDB *sql.DB)
	QueryString() string
	SetConfig(config DBConfig)
	GetConfig() DBConfig
}

DialectHandler is the primary interface that all database types must comply too

type MultiTenantDialectHandler

type MultiTenantDialectHandler struct {
	Handlers map[string]DialectHandler
}

func (MultiTenantDialectHandler) Empty

func (mtd MultiTenantDialectHandler) Empty() bool

Empty will determine if there are not database handlers present

func (*MultiTenantDialectHandler) Set

func (mtd *MultiTenantDialectHandler) Set(key string, handler DialectHandler)

Append will add database handlers to the Handlers slice

func (MultiTenantDialectHandler) SwitchDB

func (mtd MultiTenantDialectHandler) SwitchDB(database string) DialectHandler

Switch allows the caller to alter to different databases to perform executions again

type Mysql

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

func (*Mysql) BulkDelete added in v1.0.1

func (m *Mysql) BulkDelete(model any) error

func (*Mysql) Create

func (m *Mysql) Create(model any) error

func (*Mysql) Delete

func (m *Mysql) Delete(model any) error

func (*Mysql) Find

func (m *Mysql) Find(model any, args ...any) error

func (*Mysql) GetConfig added in v1.0.3

func (m *Mysql) GetConfig() DBConfig

func (*Mysql) QueryString

func (m *Mysql) QueryString() string

func (*Mysql) Raw

func (m *Mysql) Raw(query string, args ...any) (*RawQuery, error)

func (*Mysql) SetConfig added in v1.0.3

func (m *Mysql) SetConfig(config DBConfig)

func (*Mysql) SetDB

func (m *Mysql) SetDB(connDB *sql.DB)

Alters the database that queries are for.

func (*Mysql) Update

func (m *Mysql) Update(model any) error

func (*Mysql) Where

func (m *Mysql) Where(model any, stmt string, limit int, args ...any) error

type Postgres

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

func (*Postgres) BulkDelete added in v1.0.1

func (pd *Postgres) BulkDelete(model any) error

func (*Postgres) Create

func (pd *Postgres) Create(model any) error

func (*Postgres) Delete

func (pd *Postgres) Delete(model any) error

func (*Postgres) Find

func (pd *Postgres) Find(model any, args ...any) error

func (*Postgres) GetConfig added in v1.0.3

func (pd *Postgres) GetConfig() DBConfig

func (*Postgres) QueryString

func (pd *Postgres) QueryString() string

func (*Postgres) Raw

func (pd *Postgres) Raw(query string, args ...any) (*RawQuery, error)

func (*Postgres) SetConfig added in v1.0.3

func (pd *Postgres) SetConfig(config DBConfig)

func (*Postgres) SetDB

func (pd *Postgres) SetDB(connDB *sql.DB)

func (*Postgres) Update

func (pd *Postgres) Update(model any) error

func (*Postgres) Where

func (pd *Postgres) Where(model any, stmt string, limit int, args ...any) error

type RawQuery

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

func Raw

func Raw(db *sql.DB, query string, args ...any) (*RawQuery, error)

Raw builds a raw query, allowing for a user to either call Exec or All functions to perform execution

func (*RawQuery) All

func (rq *RawQuery) All(model any) error

All will accept a model, perform the query, and attempt to fill any data values into the given model.

func (*RawQuery) Exec

func (rq *RawQuery) Exec() error

Executes given query strig to perform which ever action the query denotes

type SQLite

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

func (*SQLite) BulkDelete added in v1.0.1

func (s *SQLite) BulkDelete(model any) error

func (*SQLite) Create

func (s *SQLite) Create(model any) error

func (*SQLite) Delete

func (s *SQLite) Delete(model any) error

func (*SQLite) Find

func (s *SQLite) Find(model any, args ...any) error

func (*SQLite) GetConfig added in v1.0.3

func (s *SQLite) GetConfig() DBConfig

func (*SQLite) QueryString

func (s *SQLite) QueryString() string

func (*SQLite) Raw

func (s *SQLite) Raw(query string, args ...any) (*RawQuery, error)

func (*SQLite) SetConfig added in v1.0.3

func (s *SQLite) SetConfig(config DBConfig)

func (*SQLite) SetDB

func (s *SQLite) SetDB(connDB *sql.DB)

func (*SQLite) Update

func (s *SQLite) Update(model any) error

func (*SQLite) Where

func (s *SQLite) Where(model any, stmt string, limit int, args ...any) error

Jump to

Keyboard shortcuts

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