clients

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CreateType          = "CREATE"
	AlterType           = "ALTER"
	RenameType          = "RENAME"
	DropType            = "DROP"
	SelectType          = "SELECT"
	InsertType          = "INSERT"
	UpdateType          = "UPDATE"
	DeleteType          = "DELETE"
	TransactionBegin    = "TRANSACTION_BEGIN"
	TransactionCommit   = "TRANSACTION_COMMIT"
	TransactionRollback = "TRANSACTION_ROLLBACK"

	DatabaseTypeMySQL   = "mysql"
	DatabaseTypeSqlite  = "sqlite"
	DefaultDatabaseType = DatabaseTypeSqlite
)
View Source
const OldTablePrefix = "old_"
View Source
const TempTablePrefix = "temp_"

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseClientInterface

type BaseClientInterface interface {
	Connect(config DatabaseConfig) (client BaseClientInterface, err error)
	Disconnect() error
	GetClient() *sql.DB
	ToSql(query QueryInterface) string
	Execute(query QueryInterface) (result dto.BaseResult, err error)
	// contains filtered or unexported methods
}

BaseClientInterface the main interface for the client

func InitClient added in v1.0.2

func InitClient(config DatabaseConfig) (BaseClientInterface, error)

InitClient method can be used for the database client init

type DatabaseConfig

type DatabaseConfig struct {
	Host     string
	Database string
	Username string
	Password string
	Port     int64
	Engine   string
	Charset  string
	Collate  string
	Type     string
}

DatabaseConfig the config which will be used by the client

func (DatabaseConfig) GetCharset added in v1.0.1

func (c DatabaseConfig) GetCharset() string

func (DatabaseConfig) GetCollate added in v1.0.1

func (c DatabaseConfig) GetCollate() string

func (DatabaseConfig) GetEngine added in v1.0.1

func (c DatabaseConfig) GetEngine() string

func (DatabaseConfig) GetType added in v1.0.2

func (c DatabaseConfig) GetType() string

type MySQLClient added in v1.0.1

type MySQLClient struct {
	Client *sql.DB
	Config DatabaseConfig
}

MySQLClient the SQLite client

func (MySQLClient) Connect added in v1.0.1

func (c MySQLClient) Connect(config DatabaseConfig) (client BaseClientInterface, err error)

func (MySQLClient) Disconnect added in v1.0.1

func (c MySQLClient) Disconnect() error

func (MySQLClient) Execute added in v1.0.1

func (c MySQLClient) Execute(q QueryInterface) (result dto.BaseResult, err error)

func (MySQLClient) GetClient added in v1.0.1

func (c MySQLClient) GetClient() *sql.DB

func (MySQLClient) ToSql added in v1.0.1

func (c MySQLClient) ToSql(q QueryInterface) string

type Query

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

Query the query object of the SQLite client

func (*Query) AddBinding

func (q *Query) AddBinding(field query.Bind) QueryInterface

AddBinding the method which identifies which foreign key we need to add for selected model in Alter method

func (*Query) AddColumn

func (q *Query) AddColumn(column dto.ModelField) QueryInterface

AddColumn the method which identifies which field we need to add for selected model in Alter method

func (*Query) AddForeignKey

func (q *Query) AddForeignKey(field dto.ForeignKey) QueryInterface

AddForeignKey the method which identifies which foreign key we need to add for selected model in Alter method

func (*Query) AddIndex

func (q *Query) AddIndex(field dto.Index) QueryInterface

AddIndex the method which identifies which index key we need to add for selected model in Alter method

func (*Query) Alter

func (q *Query) Alter(model dto.ModelInterface) QueryInterface

Alter method should be used when you need to alter selected table. It should be used from the beginning of your query, to specify the initial query string and with combination one of the methods AddColumn, DropColumn, AddIndex, DropIndex, AddForeignKey, DropForeignKey This method receives the dto.ModelInterface object and returns the updated query.AlterQuery object.

func (*Query) BeginTransaction added in v1.2.4

func (q *Query) BeginTransaction() QueryInterface

func (*Query) CommitTransaction added in v1.2.4

func (q *Query) CommitTransaction() QueryInterface

func (*Query) Create

func (q *Query) Create(model dto.ModelInterface) QueryInterface

Create method will return the query object for table creation

func (*Query) Delete

func (q *Query) Delete() QueryInterface

Delete method deletes the row.

func (*Query) Drop

func (q *Query) Drop(model dto.ModelInterface) QueryInterface

Drop method will return the query object for table drop

func (*Query) DropColumn

func (q *Query) DropColumn(column dto.ModelField) QueryInterface

DropColumn the method which identifies which field we need to drop for selected model in Alter method

func (*Query) DropForeignKey

func (q *Query) DropForeignKey(field dto.ForeignKey) QueryInterface

DropForeignKey the method which identifies which foreign key we need to drop for selected model in Alter method

func (*Query) DropIndex

func (q *Query) DropIndex(field dto.Index) QueryInterface

DropIndex the method which identifies which index key we need to add for selected model in Alter method

func (*Query) From

func (q *Query) From(model interface{}) QueryInterface

From using this method you can specify the ORDER BY fields with the right direction to order.

func (*Query) GetBindings

func (q *Query) GetBindings() []query.Bind

func (*Query) GetColumns

func (q *Query) GetColumns() []interface{}

func (*Query) GetColumnsToDrop

func (q *Query) GetColumnsToDrop() []interface{}

func (*Query) GetDestination

func (q *Query) GetDestination() dto.ModelInterface

func (*Query) GetForeignKeysToAdd

func (q *Query) GetForeignKeysToAdd() []dto.ForeignKey

func (*Query) GetForeignKeysToDrop

func (q *Query) GetForeignKeysToDrop() []dto.ForeignKey

func (*Query) GetGroupBy

func (q *Query) GetGroupBy() []string

func (*Query) GetIfNotExists added in v1.1.2

func (q *Query) GetIfNotExists() bool

GetIfNotExists method can be used in the combination with CREATE TABLE statement to have condition CREATE TABLE IF NOT EXISTS

func (*Query) GetIndexesToAdd

func (q *Query) GetIndexesToAdd() []dto.Index

func (*Query) GetIndexesToDrop

func (q *Query) GetIndexesToDrop() []dto.Index

func (*Query) GetJoins

func (q *Query) GetJoins() []query.Join

func (*Query) GetLimit

func (q *Query) GetLimit() query.Limit

func (*Query) GetNewTableName added in v1.1.1

func (q *Query) GetNewTableName() string

func (*Query) GetOrderBy

func (q *Query) GetOrderBy() []query.OrderByColumn

func (*Query) GetQueryType

func (q *Query) GetQueryType() string

func (*Query) GetValues added in v1.1.1

func (q *Query) GetValues() interface{}

GetValues retrieves the values added by Values method

func (*Query) GetWheres

func (q *Query) GetWheres() []query.Where

func (*Query) GroupBy

func (q *Query) GroupBy(field string) QueryInterface

GroupBy using this method you can specify the fields for the GROUP BY clause.

func (*Query) IfNotExists added in v1.1.2

func (q *Query) IfNotExists() QueryInterface

IfNotExists sets the ifNotExists flag. method can be used in the combination with CREATE TABLE statement to have condition CREATE TABLE IF NOT EXISTS

func (*Query) Insert

func (q *Query) Insert(model dto.ModelInterface) QueryInterface

Insert method should be used when you need to insert something into selected table. It should be used from the beginning of your query, to specify the initial query string. This method receives the dto.ModelInterface object and returns the last inserted ID and error(if it exists)

func (*Query) Join

func (q *Query) Join(join query.Join) QueryInterface

Join method can be used for specification of JOIN clause.

func (*Query) Limit

func (q *Query) Limit(limit query.Limit) QueryInterface

Limit using this method you can set the limitation for result of your query

func (*Query) OrderBy

func (q *Query) OrderBy(field string, direction string) QueryInterface

OrderBy using this method you can specify the ORDER BY fields with the right direction to order.

func (*Query) Rename added in v1.1.1

func (q *Query) Rename(table string, newTableName string) QueryInterface

Rename will rename the table to the new table name

func (*Query) RollbackTransaction added in v1.2.4

func (q *Query) RollbackTransaction() QueryInterface

func (*Query) Select

func (q *Query) Select(columns interface{}) QueryInterface

Select using that method you can set the attributes for selection. This method should be used from the beginning of your query, to specify the initial query string. This method returns the updated Query object.

func (*Query) Update

func (q *Query) Update(model dto.ModelInterface) QueryInterface

Update method should be used when you need to update something in your selected table. It should be used from the beginning of your query, to specify the initial query string. This method receives the dto.ModelInterface object and returns the updated query.UpdateQuery object.

func (*Query) Values added in v1.1.1

func (q *Query) Values(values interface{}) QueryInterface

Values sets the values, which will be used for insert queries

func (*Query) Where

func (q *Query) Where(where query.Where) QueryInterface

Where method needed for WHERE clause configuration.

type QueryInterface

type QueryInterface interface {
	//Create method will return the query object for table creation
	Create(dto.ModelInterface) QueryInterface

	//Drop method will return the query object for table drop
	Drop(dto.ModelInterface) QueryInterface

	//Select using that method you can set the attributes for selection. This method should be used from the beginning of your query, to specify the initial query string.
	//This method returns the updated Query object.
	Select(columns interface{}) QueryInterface

	//Insert method should be used when you need to insert something into selected table.
	//It should be used from the beginning of your query, to specify the initial query string.
	//This method receives the dto.ModelInterface object and returns the last inserted ID and error(if it exists)
	Insert(dto.ModelInterface) QueryInterface

	//Update method should be used when you need to update something in your selected table.
	//It should be used from the beginning of your query, to specify the initial query string.
	//This method receives the dto.ModelInterface object and returns the updated QueryInterface object.
	Update(dto.ModelInterface) QueryInterface

	//Alter method should be used when you need to alter selected table.
	//It should be used from the beginning of your query, to specify the initial query string and with combination one of the methods AddColumn, DropColumn, AddIndex, DropIndex, AddForeignKey, DropForeignKey
	//This method receives the dto.ModelInterface object and returns the updated QueryInterface object.
	Alter(dto.ModelInterface) QueryInterface

	//Rename method renames the table to a new table name
	Rename(original string, newTableName string) QueryInterface

	//Delete method deletes the row.
	Delete() QueryInterface

	//GetQueryType Returns the type of the Query. Eg: INSERT, ALTER, SELECT, DELETE, CREATE, UPDATE, DROP
	GetQueryType() string
	GetNewTableName() string
	GetDestination() dto.ModelInterface
	GetColumns() []interface{}
	GetColumnsToDrop() []interface{}
	GetForeignKeysToAdd() []dto.ForeignKey
	GetForeignKeysToDrop() []dto.ForeignKey
	GetIndexesToAdd() []dto.Index
	GetIndexesToDrop() []dto.Index
	GetWheres() []query.Where
	GetJoins() []query.Join
	GetOrderBy() []query.OrderByColumn
	GetGroupBy() []string
	GetLimit() query.Limit

	Values(interface{}) QueryInterface
	GetValues() interface{}

	//From using this method you can specify the ORDER BY fields with the right direction to order.
	From(model interface{}) QueryInterface

	//IfNotExists Sets the IfNotExists flag. Method can be used in the combination with CREATE TABLE statement to have condition CREATE TABLE IF NOT EXISTS
	IfNotExists() QueryInterface

	//GetIfNotExists method can be used in the combination with CREATE TABLE statement to have condition CREATE TABLE IF NOT EXISTS
	GetIfNotExists() bool

	//OrderBy using this method you can specify the ORDER BY fields with the right direction to order.
	OrderBy(field string, direction string) QueryInterface

	Limit(limit query.Limit) QueryInterface

	//GroupBy using this method you can specify the fields for the GROUP BY clause.
	GroupBy(field string) QueryInterface

	//Where method needed for WHERE clause configuration.
	Where(where query.Where) QueryInterface

	//Join method can be used for specification of JOIN clause.
	Join(join query.Join) QueryInterface

	//AddColumn the method which identifies which field we need to add for selected model in Alter method
	AddColumn(column dto.ModelField) QueryInterface

	AddBinding(query.Bind) QueryInterface

	//DropColumn the method which identifies which field we need to drop for selected model in Alter method
	DropColumn(dto.ModelField) QueryInterface

	//AddForeignKey the method which identifies which foreign key we need to add for selected model in Alter method
	AddForeignKey(field dto.ForeignKey) QueryInterface

	//DropForeignKey the method which identifies which foreign key we need to drop for selected model in Alter method
	DropForeignKey(field dto.ForeignKey) QueryInterface

	//AddIndex the method which identifies which index key we need to add for selected model in Alter method
	AddIndex(index dto.Index) QueryInterface

	//DropIndex the method which identifies which index key we need to add for selected model in Alter method
	DropIndex(index dto.Index) QueryInterface

	//GetBindings method returns the binding collected during the query building
	GetBindings() []query.Bind

	//BeginTransaction begins the transaction
	BeginTransaction() QueryInterface

	//CommitTransaction commits the transaction
	CommitTransaction() QueryInterface

	//RollbackTransaction rollbacks the transaction
	RollbackTransaction() QueryInterface
}

QueryInterface the interface for the query builder of the client

type SQLiteClient

type SQLiteClient struct {
	Client *sql.DB
	Config DatabaseConfig
}

SQLiteClient the SQLite client

func (SQLiteClient) Connect

func (c SQLiteClient) Connect(config DatabaseConfig) (client BaseClientInterface, err error)

func (SQLiteClient) Disconnect

func (c SQLiteClient) Disconnect() error

func (SQLiteClient) Execute

func (c SQLiteClient) Execute(q QueryInterface) (result dto.BaseResult, err error)

func (SQLiteClient) GetClient

func (c SQLiteClient) GetClient() *sql.DB

func (SQLiteClient) ToSql

func (c SQLiteClient) ToSql(q QueryInterface) string

Jump to

Keyboard shortcuts

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