Documentation
¶
Index ¶
- Constants
- func DatabaseDriverName(db *sql.DB) string
- func TableCreate(db *sql.DB, tableName string, columns []Column) error
- func TableCreateSql(db *sql.DB, tableName string, columns []Column) string
- func TableDrop(ctx database.QueryableContext, tableName string) error
- func TableDropIfExists(ctx database.QueryableContext, tableName string) error
- func TableDropIfExistsSql(ctx database.QueryableContext, tableName string) (string, error)
- func TableDropSql(ctx database.QueryableContext, tableName string) (string, error)
- type Builder
- func (b *Builder) Column(column Column) BuilderInterface
- func (b *Builder) Create() string
- func (b *Builder) CreateIfNotExists() string
- func (b *Builder) CreateIndex(indexName string, columnName ...string) string
- func (b *Builder) Delete() string
- func (b *Builder) Drop() string
- func (b *Builder) DropIfExists() string
- func (b *Builder) GroupBy(groupBy GroupBy) BuilderInterface
- func (b *Builder) Insert(columnValuesMap map[string]string) string
- func (b *Builder) Limit(limit int64) BuilderInterface
- func (b *Builder) Offset(offset int64) BuilderInterface
- func (b *Builder) OrderBy(columnName, direction string) BuilderInterface
- func (b *Builder) Select(columns []string) string
- func (b *Builder) Table(tableName string) BuilderInterface
- func (b *Builder) TableColumnAdd(tableName string, column Column) (sql string, err error)
- func (b *Builder) TableColumnRename(tableName, oldColumnName, newColumnName string) (sql string, err error)
- func (b *Builder) TableRename(oldTableName, newTableName string) (sql string, err error)
- func (b *Builder) Truncate() string
- func (b *Builder) Update(columnValues map[string]string) string
- func (b *Builder) View(viewName string) BuilderInterface
- func (b *Builder) ViewColumns(columns []string) BuilderInterface
- func (b *Builder) ViewSQL(sql string) BuilderInterface
- func (b *Builder) Where(where Where) BuilderInterface
- type BuilderInterface
- type Column
- type Database
- func (d *Database) BeginTransaction() (err error)
- func (d *Database) BeginTransactionWithContext(ctx context.Context, opts *sql.TxOptions) (err error)
- func (d *Database) Close() (err error)
- func (d *Database) CommitTransaction() (err error)
- func (d *Database) DB() *sql.DB
- func (d *Database) DebugEnable(debug bool)
- func (d *Database) Exec(sqlStr string, args ...any) (sql.Result, error)
- func (d *Database) ExecInTransaction(fn func(d *Database) error) (err error)
- func (d *Database) IsMssql() bool
- func (d *Database) IsMysql() bool
- func (d *Database) IsPostgres() bool
- func (d *Database) IsSqlite() bool
- func (d *Database) Open() (err error)
- func (d *Database) Query(sqlStr string, args ...any) (*sql.Rows, error)
- func (d *Database) RollbackTransaction() (err error)
- func (d *Database) SelectToMapAny(sqlStr string, args ...any) ([]map[string]any, error)
- func (d *Database) SelectToMapString(sqlStr string, args ...any) ([]map[string]string, error)
- func (d *Database) SqlLog() []map[string]string
- func (d *Database) SqlLogEmpty()
- func (d *Database) SqlLogEnable(enable bool)
- func (d *Database) SqlLogLen() int
- func (d *Database) SqlLogShrink(leaveLast int)
- func (d *Database) Tx() *sql.Tx
- func (d *Database) Type() string
- type DatabaseInterface
- type GroupBy
- type OrderBy
- type Where
Constants ¶
View Source
const ASC = "asc"
Sortable
View Source
const COLUMN_ATTRIBUTE_AUTO = "auto"
Column Attributes
View Source
const COLUMN_ATTRIBUTE_DECIMALS = "decimals"
View Source
const COLUMN_ATTRIBUTE_LENGTH = "length"
View Source
const COLUMN_ATTRIBUTE_NULLABLE = "nullable"
View Source
const COLUMN_ATTRIBUTE_PRIMARY = "primary"
View Source
const COLUMN_TYPE_BLOB = "blob"
Column Types
View Source
const COLUMN_TYPE_DATE = "date"
View Source
const COLUMN_TYPE_DATETIME = "datetime"
View Source
const COLUMN_TYPE_DECIMAL = "decimal"
View Source
const COLUMN_TYPE_FLOAT = "float"
View Source
const COLUMN_TYPE_INTEGER = "integer"
View Source
const COLUMN_TYPE_LONGTEXT = "longtext"
View Source
const COLUMN_TYPE_STRING = "string"
View Source
const COLUMN_TYPE_TEXT = "text"
View Source
const DESC = "desc"
View Source
const DIALECT_MSSQL = "mssql"
Dialects
View Source
const DIALECT_MYSQL = "mysql"
View Source
const DIALECT_POSTGRES = "postgres"
View Source
const DIALECT_SQLITE = "sqlite"
View Source
const MAX_DATE = "9999-12-31"
View Source
const MAX_DATETIME = "9999-12-31 23:59:59"
View Source
const NO = "no"
View Source
const NULL_DATE = "0002-01-01"
Null time (earliest valid date in Gregorian calendar is 1AD, no year 0)
View Source
const NULL_DATETIME = "0002-01-01 00:00:00"
View Source
const YES = "yes"
Common
Variables ¶
This section is empty.
Functions ¶
func DatabaseDriverName ¶
DatabaseDriverName finds the driver name from database
func TableCreate ¶ added in v0.7.0
func TableCreateSql ¶ added in v0.7.0
func TableDrop ¶ added in v0.7.0
func TableDrop(ctx database.QueryableContext, tableName string) error
func TableDropIfExists ¶ added in v0.7.0
func TableDropIfExists(ctx database.QueryableContext, tableName string) error
func TableDropIfExistsSql ¶ added in v0.7.0
func TableDropIfExistsSql(ctx database.QueryableContext, tableName string) (string, error)
func TableDropSql ¶ added in v0.7.0
func TableDropSql(ctx database.QueryableContext, tableName string) (string, error)
Types ¶
type Builder ¶
type Builder struct { Dialect string // contains filtered or unexported fields }
func NewBuilder ¶
func (*Builder) Column ¶
func (b *Builder) Column(column Column) BuilderInterface
func (*Builder) Create ¶
*
- The create method creates new database or table.
- If the database or table can not be created it will return false.
- False will be returned if the database or table already exist.
- <code>
- // Creating a new database
- $database->create(); *
- // Creating a new table
- $database->table("STATES")
- ->column("STATE_NAME","STRING")
- ->create();
- </code>
- @return boolean true, on success, false, otherwise
- @access public
func (*Builder) CreateIfNotExists ¶
func (*Builder) CreateIndex ¶ added in v0.6.0
func (*Builder) Delete ¶
*
- The delete method deletes a row in a table. For deleting a database
- or table use the drop method.
- <code>
- // Deleting a row
- sql := builder.Table("STATES").Where("STATE_NAME","=","Alabama").Delete();
- </code>
- @return string
- @access public
Drop deletes a table
func (*Builder) DropIfExists ¶
func (*Builder) GroupBy ¶
func (b *Builder) GroupBy(groupBy GroupBy) BuilderInterface
func (*Builder) Insert ¶
*
- The <b>update</b> method updates the values of a row in a table.
- <code>
- $updated_user = array("USER_MANE"=>"Mike");
- $database->table("USERS")->where("USER_NAME","==","Peter")->update($updated_user);
- </code>
- @param Array an associative array, where keys are the column names of the table
- @return int 0 or 1, on success, false, otherwise
- @access public
func (*Builder) Limit ¶
func (b *Builder) Limit(limit int64) BuilderInterface
func (*Builder) Offset ¶
func (b *Builder) Offset(offset int64) BuilderInterface
func (*Builder) OrderBy ¶
func (b *Builder) OrderBy(columnName, direction string) BuilderInterface
func (*Builder) Select ¶
* The <b>select</b> method selects rows from a table, based on criteria.
- <code>
- // Selects all the rows from the table
- $db->table("USERS")->select(); *
- // Selects the rows where the column NAME is different from Peter, in descending order
- $db->table("USERS")
- ->where("NAME","!=","Peter")
- ->orderby("NAME","desc")
- ->select();
- </code>
- @return mixed rows as associative array, false on error
- @access public
func (*Builder) Table ¶
func (b *Builder) Table(tableName string) BuilderInterface
func (*Builder) TableColumnAdd ¶ added in v0.7.0
func (*Builder) TableColumnRename ¶ added in v0.7.0
func (*Builder) TableRename ¶ added in v0.7.0
Rename renames a table or a view
func (*Builder) Update ¶
*
- The <b>update</b> method updates the values of a row in a table.
- <code>
- $updated_user = array("USER_MANE"=>"Mike");
- $database->table("USERS")->where("USER_NAME","==","Peter")->update($updated_user);
- </code>
- @param Array an associative array, where keys are the column names of the table
- @return int 0 or 1, on success, false, otherwise
- @access public
func (*Builder) View ¶
func (b *Builder) View(viewName string) BuilderInterface
func (*Builder) ViewColumns ¶
func (b *Builder) ViewColumns(columns []string) BuilderInterface
func (*Builder) ViewSQL ¶
func (b *Builder) ViewSQL(sql string) BuilderInterface
func (*Builder) Where ¶
func (b *Builder) Where(where Where) BuilderInterface
type BuilderInterface ¶ added in v0.7.0
type BuilderInterface interface { Column(column Column) BuilderInterface Create() string CreateIfNotExists() string CreateIndex(indexName string, columnName ...string) string Delete() string Drop() string DropIfExists() string Insert(columnValuesMap map[string]string) string GroupBy(groupBy GroupBy) BuilderInterface Limit(limit int64) BuilderInterface Offset(offset int64) BuilderInterface OrderBy(columnName string, sortDirection string) BuilderInterface Select(columns []string) string Table(name string) BuilderInterface Update(columnValues map[string]string) string View(name string) BuilderInterface ViewColumns(columns []string) BuilderInterface ViewSQL(sql string) BuilderInterface Where(where Where) BuilderInterface TableRename(oldTableName string, newTableName string) (string, error) TableColumnAdd(tableName string, column Column) (string, error) TableColumnRename(tableName, oldColumnName, newColumnName string) (string, error) }
type Column ¶
type Column struct { Name string Type string Length int Decimals int AutoIncrement bool PrimaryKey bool Nullable bool Unique bool Default string }
func TableColumns ¶ added in v0.7.0
func TableColumns(ctx database.QueryableContext, tableName string, commonize bool) (columns []Column, err error)
TableColumns returns a list of columns for a given table name
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func (*Database) BeginTransaction ¶
func (*Database) BeginTransactionWithContext ¶
func (*Database) CommitTransaction ¶
func (*Database) DebugEnable ¶
func (*Database) ExecInTransaction ¶
func (*Database) IsPostgres ¶ added in v0.7.0
func (*Database) RollbackTransaction ¶
func (*Database) SelectToMapAny ¶
func (*Database) SelectToMapString ¶
func (*Database) SqlLogEmpty ¶
func (d *Database) SqlLogEmpty()
func (*Database) SqlLogEnable ¶
func (*Database) SqlLogShrink ¶
type DatabaseInterface ¶ added in v0.7.0
type DatabaseInterface interface { // DB the database connection DB() *sql.DB // Type the database type, i.e. "mssql", "mysql", "postgres", "sqlite" Type() string // BeginTransaction starts a transaction BeginTransaction() (err error) // BeginTransactionWithContext starts a transaction with context BeginTransactionWithContext(ctx context.Context, opts *sql.TxOptions) (err error) // Close closes the database Close() (err error) // CommitTransaction commits the transaction CommitTransaction() (err error) // DebugEnable enables or disables debug DebugEnable(debug bool) // ExecInTransaction executes a function in a transaction ExecInTransaction(fn func(d *Database) error) (err error) // Exec executes a query Exec(sqlStr string, args ...any) (sql.Result, error) IsMssql() bool IsMysql() bool IsPostgres() bool IsSqlite() bool SqlLog() []map[string]string SqlLogEmpty() SqlLogLen() int SqlLogEnable(enable bool) SqlLogShrink(leaveLast int) Open() (err error) Query(sqlStr string, args ...any) (*sql.Rows, error) RollbackTransaction() (err error) SelectToMapAny(sqlStr string, args ...any) ([]map[string]any, error) SelectToMapString(sqlStr string, args ...any) ([]map[string]string, error) // Tx the transaction Tx() *sql.Tx }
func NewDatabase ¶
func NewDatabase(db *sql.DB, databaseType string) DatabaseInterface
func NewDatabaseFromDriver ¶
func NewDatabaseFromDriver(driverName, dataSourceName string) (DatabaseInterface, error)
Click to show internal directories.
Click to hide internal directories.