Documentation
¶
Index ¶
- Constants
- Variables
- func AddSessionParams(db *sql.DB, params map[string]string, originals ...bool) (keys []string, err error)
- func BuildUrl(server string, port int, service, user, password string, ...) string
- func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]interface{}) (values clause.Values)
- func ConvertSliceOfMapToValuesForCreate(stmt *gorm.Statement, mapValues []map[string]interface{}) (values clause.Values)
- func ConvertToAssignments(stmt *gorm.Statement) (set clause.Set)
- func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values)
- func Create(db *gorm.DB)
- func DelSessionParams(db *sql.DB, keys []string)
- func Delete(db *gorm.DB)
- func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, ...) string
- func GetStringExpr(value string, quotes ...bool) clause.Expr
- func IsExplicitQuoted(part string) (inner string, ok bool)
- func IsReservedWord(v string) bool
- func IsSafeOracleUnquoted(s string) bool
- func MergeCreate(db *gorm.DB, onConflict clause.OnConflict, values clause.Values)
- func New(config Config) gorm.Dialector
- func Open(dsn string) gorm.Dialector
- func Query(db *gorm.DB)
- func Scan(rows gorm.Rows, db *gorm.DB, mode gorm.ScanMode)
- func Update(db *gorm.DB)
- type Case
- type Config
- type DataSet
- type Dialector
- func (d Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, _ interface{})
- func (d Dialector) ClauseBuilders() (clauseBuilders map[string]clause.ClauseBuilder)
- func (d Dialector) DataTypeOf(field *schema.Field) string
- func (d Dialector) DefaultValueOf(*schema.Field) clause.Expression
- func (d Dialector) DummyTableName() string
- func (d Dialector) Explain(sql string, vars ...interface{}) string
- func (d Dialector) Initialize(db *gorm.DB) (err error)
- func (d Dialector) Migrator(db *gorm.DB) gorm.Migrator
- func (d Dialector) Name() string
- func (d Dialector) QuoteTo(w clause.Writer, s string)
- func (d Dialector) RewriteLimit(c clause.Clause, builder clause.Builder)
- func (d Dialector) RewriteLimit11(c clause.Clause, builder clause.Builder)
- func (d Dialector) RollbackTo(tx *gorm.DB, name string) error
- func (d Dialector) SavePoint(tx *gorm.DB, name string) error
- func (d Dialector) Translate(err error) error
- type Migrator
- func (m Migrator) AddColumn(value interface{}, field string) error
- func (m Migrator) AlterColumn(value interface{}, field string) error
- func (m Migrator) AlterDataTypeOf(stmt *gorm.Statement, field *schema.Field) (expr clause.Expr)
- func (m Migrator) AutoMigrate(dst ...interface{}) error
- func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})
- func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
- func (m Migrator) CreateConstraint(value interface{}, name string) error
- func (m Migrator) CreateIndex(value interface{}, name string) error
- func (m Migrator) CreateTable(values ...interface{}) error
- func (m Migrator) CurrentDatabase() (name string)
- func (m Migrator) DropColumn(value interface{}, name string) error
- func (m Migrator) DropConstraint(value interface{}, name string) error
- func (m Migrator) DropIndex(value interface{}, name string) error
- func (m Migrator) DropTable(values ...interface{}) error
- func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr)
- func (m Migrator) GetTables() (tableList []string, err error)
- func (m Migrator) GetTypeAliases(databaseTypeName string) (types []string)
- func (m Migrator) HasColumn(value interface{}, field string) bool
- func (m Migrator) HasConstraint(value interface{}, name string) bool
- func (m Migrator) HasIndex(value interface{}, name string) bool
- func (m Migrator) HasTable(value interface{}) bool
- func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, _ gorm.ColumnType) error
- func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
- func (m Migrator) RenameTable(oldName, newName interface{}) (err error)
- type NamingStrategy
- func (ns *NamingStrategy) CheckerName(table, column string) string
- func (ns *NamingStrategy) ColumnName(_, column string) string
- func (ns *NamingStrategy) IndexName(table, column string) string
- func (ns *NamingStrategy) JoinTableName(joinTable string) string
- func (ns *NamingStrategy) RelationshipFKName(rel schema.Relationship) string
- func (ns *NamingStrategy) SchemaName(table string) string
- func (ns *NamingStrategy) TableName(str string) string
- func (ns *NamingStrategy) UniqueName(table, column string) string
- type Out
- type RefCursor
- type Replacer
- type Returning
Constants ¶
const ( NullNoop nullAction = iota NullSetNull NullSetNotNull )
Variables ¶
var ReservedWords = hashset.New[string](ReservedWordsList...)
var ReservedWordsList = []string{}/* 112 elements not displayed */
Functions ¶
func AddSessionParams ¶
func AddSessionParams(db *sql.DB, params map[string]string, originals ...bool) (keys []string, err error)
AddSessionParams setting database connection session parameters, the value is wrapped in single quotes.
If the value doesn't need to be wrapped in single quotes, please use the go_ora.AddSessionParam function directly, or pass the originals parameter as true.
func BuildUrl ¶
func BuildUrl(server string, port int, service, user, password string, options map[string]string) string
BuildUrl create databaseURL from server, port, service, user, password, urlOptions this function help build a will formed databaseURL and accept any character as it convert special charters to corresponding values in URL
func ConvertMapToValuesForCreate ¶ added in v0.4.0
func ConvertMapToValuesForCreate(stmt *gorm.Statement, mapValue map[string]interface{}) (values clause.Values)
ConvertMapToValuesForCreate convert map to values
func ConvertSliceOfMapToValuesForCreate ¶ added in v0.4.0
func ConvertSliceOfMapToValuesForCreate(stmt *gorm.Statement, mapValues []map[string]interface{}) (values clause.Values)
ConvertSliceOfMapToValuesForCreate convert slice of map to values
func ConvertToAssignments ¶
ConvertToAssignments convert to update assignments
func ConvertToCreateValues ¶ added in v0.4.0
func DelSessionParams ¶
DelSessionParams remove session parameters
func ExplainSQL ¶ added in v0.2.1
func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, avars ...interface{}) string
ExplainSQL generate SQL string with given parameters, the generated SQL is expected to be used in logger, execute it might introduce a SQL injection vulnerability
func GetStringExpr ¶
GetStringExpr replace single quotes in the string with two single quotes and return the expression for the string value
quotes : if the SQL placeholder is ? then pass true, if it is '?' then do not pass or pass false.
func IsExplicitQuoted ¶ added in v0.2.4
IsExplicitQuoted Detects explicit user-quoted literal: (example: "Name")
func IsReservedWord ¶
func IsSafeOracleUnquoted ¶ added in v0.2.4
IsSafeOracleUnquoted
Unquoted identifiers: - are stored uppercase - must begin with a letter - may contain A–Z, 0–9, _, $, # - must not be a reserved word
Input s must already be in its target case for the chosen mode.
Returns true if s can be emitted unquoted safely.
func MergeCreate ¶
Types ¶
type Config ¶
type Config struct {
DriverName string
DSN string
Conn gorm.ConnPool //*sql.DB
DefaultStringSize uint
DBVer string
// IgnoreCase applies to data; not identifiers
IgnoreCase bool // warning: may cause performance issues
// NamingCaseSensitive applies to identifiers
NamingCaseSensitive bool // whether naming is case-sensitive
// PreferredCase determines the strategy for naming identifiers; Note that setting PreferredCase to CamelCase or SnakeCase will override the NamingCaseSensitive setting; ScreamingSnakeCase is the default and works with both case-sensitive and case-insensitive naming
PreferredCase Case
// whether VARCHAR type size is character length, defaulting to byte length
VarcharSizeIsCharLength bool
// RowNumberAliasForOracle11 is the alias for ROW_NUMBER() in Oracle 11g, defaulting to ROW_NUM
RowNumberAliasForOracle11 string
UseClobForTextType bool
// time conversion for all clauses to ensure proper time rounding
TimeGranularity time.Duration
// use this timezone for the session
SessionTimezone string
// contains filtered or unexported fields
}
type Dialector ¶
type Dialector struct {
*Config
}
Dialector implement GORM database dialector
func (Dialector) ClauseBuilders ¶
func (d Dialector) ClauseBuilders() (clauseBuilders map[string]clause.ClauseBuilder)
func (Dialector) DefaultValueOf ¶
func (d Dialector) DefaultValueOf(*schema.Field) clause.Expression
func (Dialector) DummyTableName ¶
func (Dialector) QuoteTo ¶
QuoteTo writes a SQL-quoted identifier (or dotted path) to writer. When NamingCaseSensitive is true, every dot-separated part is wrapped in double quotes and any internal `"` are escaped as `""`. Existing outer quotes around parts are normalized (removed then re-applied).
func (Dialector) RewriteLimit ¶
func (Dialector) RewriteLimit11 ¶
RewriteLimit11 rewrite the LIMIT clause in the query to accommodate pagination requirements for Oracle 11g and lower database versions
Limit and Offset ¶
SELECT * FROM (SELECT T.*, ROW_NUMBER() OVER (ORDER BY column) AS ROW_NUM FROM table_name T) WHERE ROW_NUM BETWEEN offset+1 AND offset+limit
Only Limit ¶
SELECT * FROM table_name WHERE ROWNUM <= limit ORDER BY column
Only Offset ¶
SELECT * FROM table_name WHERE ROWNUM > offset ORDER BY column
type Migrator ¶
Migrator implement gorm migrator interface
func (Migrator) AddColumn ¶
AddColumn adds a column using Oracle syntax:
ALTER TABLE <t> ADD (<col …>) Then (optionally) enforce NOT NULL via a separate MODIFY to avoid data population issues.
func (Migrator) AlterColumn ¶
AlterColumn
ALTER TABLE <t> MODIFY (<col …>) Identity add/drop is done as a separate MODIFY.
func (Migrator) AlterDataTypeOf ¶
AlterDataTypeOf builds "<datatype> [DEFAULT ...] [NOT NULL]" for Oracle. It is used by generic migrator code paths; AlterColumn/AddColumn should still call their own builders.
func (Migrator) AutoMigrate ¶
AutoMigrate automatically migrate model to table structure
// Migrate and set single table comment
db.Set("gorm:table_comments", "User Information Table").AutoMigrate(&User{})
// Migrate and set multiple table comments
db.Set("gorm:table_comments", []string{"User Information Table", "Company Information Table"}).AutoMigrate(&User{}, &Company{})
func (Migrator) BuildIndexOptions ¶ added in v0.2.4
func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})
BuildIndexOptions builds the per-column list for CREATE INDEX on Oracle. Notes: - Ignore Length and Collate (not applicable). - Keep raw expressions as-is. - Use NamingStrategy to render identifiers (avoids quotes unless required). - Allow ASC/DESC [NULLS FIRST|LAST].
func (Migrator) ColumnTypes ¶
func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)
ColumnTypes via USER/ALL_TAB_COLUMNS (no driver metadata).
func (Migrator) CreateConstraint ¶
CreateConstraint ensure FK names follow oracle.NamingStrategy (genToken), and strip unsupported ON UPDATE clauses.
func (Migrator) CreateIndex ¶
func (Migrator) CreateTable ¶
CreateTable create table in database for values
func (Migrator) CurrentDatabase ¶
CurrentDatabase returns current database name
func (Migrator) DropColumn ¶
DropColumn ALTER TABLE <table> DROP COLUMN <col>
func (Migrator) DropConstraint ¶
DropConstraint ALTER TABLE <table> DROP CONSTRAINT <name>
func (Migrator) FullDataTypeOf ¶
FullDataTypeOf returns field's db full data type
func (Migrator) GetTypeAliases ¶
GetTypeAliases return database type aliases
func (Migrator) HasConstraint ¶
HasConstraint USER_CONSTRAINTS / ALL_CONSTRAINTS with dictionary casing
func (Migrator) HasIndex ¶
HasIndex USER_INDEXES / ALL_INDEXES with dictionary casing for table and index
func (Migrator) HasTable ¶
HasTable returns table existence using Oracle data dictionary. Uses dictQualifiedParts to compare OWNER/TABLE_NAME correctly for quoted vs unquoted identifiers.
func (Migrator) MigrateColumn ¶
MigrateColumn Oracle-specific. 1) ALTER via your AlterColumn (MODIFY ...). 2) Sync COMMENT ON COLUMN if model comment differs.
func (Migrator) RenameIndex ¶
RenameIndex ALTER INDEX <old> RENAME TO <new>
func (Migrator) RenameTable ¶
RenameTable rename table from oldName to newName
type NamingStrategy ¶ added in v0.2.2
type NamingStrategy struct {
TablePrefix string
SingularTable bool
NameReplacer Replacer
IdentifierMaxLength int
PreferredCase Case // default is SCREAMING_SNAKE_CASE
NamingCaseSensitive bool // whether naming is case-sensitive
// contains filtered or unexported fields
}
NamingStrategy tables, columns naming strategy
func (*NamingStrategy) CheckerName ¶ added in v0.2.2
func (ns *NamingStrategy) CheckerName(table, column string) string
CheckerName builds a CHECK constraint name: CK_<TABLE>_<COLUMN...>, capped to Oracle limits.
func (*NamingStrategy) ColumnName ¶ added in v0.2.2
func (ns *NamingStrategy) ColumnName(_, column string) string
ColumnName convert string to column name
func (*NamingStrategy) IndexName ¶ added in v0.2.2
func (ns *NamingStrategy) IndexName(table, column string) string
IndexName builds a unique index name(table, hint) -> IDX_<TABLE>_<HINT>_<FNV8>, capped to IdentifierMaxLength
func (*NamingStrategy) JoinTableName ¶ added in v0.2.2
func (ns *NamingStrategy) JoinTableName(joinTable string) string
JoinTableName applies the same rules as TableName for join tables.
func (*NamingStrategy) RelationshipFKName ¶ added in v0.2.2
func (ns *NamingStrategy) RelationshipFKName(rel schema.Relationship) string
RelationshipFKName builds a deterministic FK constraint name honoring Oracle's 30-byte cap. We generate an unqualified, safe token (A–Z, 0–9, _) and let QuoteTo add quotes only if required elsewhere.
func (*NamingStrategy) SchemaName ¶ added in v0.2.2
func (ns *NamingStrategy) SchemaName(table string) string
SchemaName returns the normalized OWNER/SCHEMA portion for a possibly-qualified table. If no explicit owner is provided, returns "".
func (*NamingStrategy) TableName ¶ added in v0.2.2
func (ns *NamingStrategy) TableName(str string) string
TableName convert string to table name
func (*NamingStrategy) UniqueName ¶ added in v0.2.2
func (ns *NamingStrategy) UniqueName(table, column string) string
UniqueName builds a unique index/constraint name: UK_<TABLE>_<COLUMN...>, capped to Oracle limits.
type Returning ¶ added in v0.2.4
type Returning struct {
Names []string
// contains filtered or unexported fields
}
func ReturningFieldsWithDefaultDBValue ¶ added in v0.2.4
func ReturningWithColumns ¶ added in v0.2.4
func ReturningWithPrimaryFields ¶ added in v0.2.4
func (Returning) MergeClause ¶ added in v0.2.4
MergeClause merge order by clauses