# README
godal/sql
Generic database/sql
DAO implementation.
Guideline
General
- DAOs must implement
IGenericDao.GdaoCreateFilter(string, IGenericBo) FilterOpt
.
Use GenericDaoSql
(and godal.IGenericBo
) directly
- Define a DAO struct that extends
GenericDaoSql
and implementsIGenericDao.GdaoCreateFilter(string, IGenericBo) FilterOpt
.
Implement custom database/sql
business DAOs and BOs
- Define and implement the business DAO (Note: DAOs must implement
IGenericDao.GdaoCreateFilter(string, IGenericBo) FilterOpt
). - Define functions to transform
godal.IGenericBo
to business BO and vice versa.
Optionally, create a helper function to create DAO instances.
Examples: see examples and examples_sta.
While this package does not use a specific SQL driver, it is highly recommended to use the following SQL drivers with
godal/sql
:
- MySQL: github.com/go-sql-driver/mysql
- MSSQL: github.com/denisenkom/go-mssqldb
- Oracle: github.com/godror/godror
- PostgreSQL: github.com/jackc/pgx
- SQLite3: github.com/mattn/go-sqlite3
# Functions
DefaultFilterOperatorTranslator is a ready-to-use implementation of FilterOperatorTranslator
Translation rule: - "equal" : = - "not equal" : <> - "greater than" : > - "greater than or equal to": >= - "less than" : < - "less than or equal to" : <= - other : error
Available since v0.5.0.
NewDeleteBuilder constructs a new DeleteBuilder.
NewGenericDaoSql constructs a new GenericDaoSql with 'txModeOnWrite=true'.
NewInsertBuilder constructs a new InsertBuilder.
NewPlaceholderGeneratorAtpiN creates a placeholder function that uses "@p<n>" as placeholder.
NewPlaceholderGeneratorColonN creates a placeholder function that uses ":<n>" as placeholder.
NewPlaceholderGeneratorDollarN creates a placeholder function that uses "$<n>" as placeholder.
NewPlaceholderGeneratorQuestion creates a placeholder function that uses "?" as placeholder.
NewSelectBuilder constructs a new SelectBuilder.
NewUpdateBuilder constructs a new UpdateBuilder.
# Constants
NameTransfIntact specifies that table column & field names are kept intact.
NameTransfLowerCase specifies that table column & field names should be lower-cased.
NameTransfUpperCase specifies that table column & field names should be upper-cased.
# Structs
BaseSqlBuilder is the base struct to implement DeleteBuilder, InsertBuilder, SelectBuilder and UpdateBuilder.
DeleteBuilder is a builder that helps to build DELETE sql statement.
FilterAnd combines two or more filters using AND clause.
FilterAndOr combines two or more filters using AND/OR clause.
FilterAsIs represents a single filter where the clause is passed as-is to the database driver.
FilterBetween represents the single filter: <field> BETWEEN <value1> AND <value2>.
FilterExpression represents the single filter: <left> <operator> <right>.
FilterFieldValue represents the single filter: <field> <operator> <value>.
FilterIsNotNull represents the single filter: <field> IS NOT NULL.
FilterIsNull represents the single filter: <field> IS NULL.
FilterOr combines two filters using OR clause.
GenericDaoSql is 'database/sql' implementation of godal.IGenericDao & IGenericDaoSql.
GenericRowMapperSql is a generic implementation of godal.IRowMapper for 'database/sql'.
GenericSorting is a generic implementation of ISorting.
InsertBuilder is a builder that helps building INSERT sql statement.
OptBetweenGenerator is used to specify the generator used to generate custom "BETWEEN" clause of the SQL statement.
OptDbFlavor is used to specify the db flavor that affects the generated SQL statement.
OptTableAlias is used to prefix table alias to field name when building ISorting, IFilter or ISqlBuilder.
SelectBuilder is a builder that helps building SELECT sql statement.
UpdateBuilder is a builder that helps building INSERT sql statement.
# Interfaces
IFilter provides API interface to build element of 'WHERE' clause for SQL statement.
IGenericDaoSql is 'database/sql' reference implementation of godal.IGenericDao.
ISorting provides API interface to build elements of 'ORDER BY' clause.
ISqlBuilder provides API interface to build the SQL statement.
# Type aliases
FilterOperatorTranslator takes a godal.FilterOperator and translates to database-compatible operator string.
NameTransformation specifies how table column name is transformed.
NewPlaceholderGenerator is a function that creates PlaceholderGenerator instances.
PlaceholderGenerator is a function that generates placeholder used in prepared statement.
StmGeneratorBetween generates custom "BETWEEN" clause of the SQL statement.