oracle

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: UPL-1.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ClauseInsert     = "INSERT"
	ClauseUpdate     = "UPDATE"
	ClauseDelete     = "DELETE"
	ClauseLimit      = "LIMIT"
	ClauseOnConflict = "ON CONFLICT"
	ClauseValues     = "VALUES"
	ClauseReturning  = "RETURNING"
)
View Source
const DefaultDriverName string = "godror"

Variables

This section is empty.

Functions

func BeforeQuery added in v0.2.0

func BeforeQuery(db *gorm.DB)

func Create

func Create(db *gorm.DB)

Create overrides GORM's create callback for Oracle.

Behavior:

  • If the schema has fields with default DB values and only one row is being inserted, it builds an INSERT ... RETURNING statement.
  • If no RETURNING is needed, it emits a standard INSERT.
  • If multiple rows require RETURNING, it builds a PL/SQL block using FORALL and BULK COLLECT; if an ON CONFLICT clause is present and resolvable, it emits a MERGE.
  • For that last case, it validates Dest (non-nil, non-empty slice with no nil elements), normalizes bind variables for Oracle, and populates destinations from OUT parameters.

Register with:

db.Callback().Create().Replace("gorm:create", oracle.Create)

func Delete

func Delete(db *gorm.DB)

Delete overrides GORM's delete callback for Oracle.

Delete builds a safe, Oracle-compatible DELETE that supports soft deletes, hard deletes, and optional RETURNING of deleted rows.

Behavior:

  • DELETE safety: checks for missing WHERE conditions and refuses to run unless AllowGlobalUpdate is set or the WHERE clause has meaningful conditions.
  • Soft delete: if the model has a soft-delete field and Unscoped is false, it lets GORM emit the UPDATE that marks rows as deleted. If a RETURNING clause is present with soft delete, it executes via QueryContext so the returned columns can be scanned.
  • Hard delete + RETURNING: it emits a PL/SQL block that performs DELETE … RETURNING BULK COLLECT INTO, wiring per-row sql.Out destinations so the deleted rows (or selected columns) can be populated back into the destination slice.
  • Hard delete (no RETURNING): it emits a standard DELETE and executes it via ExecContext.
  • Expressions: it expands WHERE expressions, including IN with slices, and normalizes bind variables for Oracle.

Register with:

db.Callback().Delete().Replace("gorm:delete", oracle.Delete)

func DeleteClauseBuilder

func DeleteClauseBuilder(c clause.Clause, builder clause.Builder)

DeleteClauseBuilder builds the DELETE clause

func InsertClauseBuilder

func InsertClauseBuilder(c clause.Clause, builder clause.Builder)

InsertClauseBuilder builds the INSERT INTO cluase

func LimitClauseBuilder

func LimitClauseBuilder(c clause.Clause, builder clause.Builder)

LimitClauseBuilder builds the Oracle FETCH clause instead of using the default LIMIT syntax The FETCH syntax is supported in Oracle 12c and later

func MismatchedCaseHandler added in v0.2.0

func MismatchedCaseHandler(gormDB *gorm.DB)

MismatchedCaseHandler handles Oracle Case Insensitivity. When identifiers are not quoted, columns are returned by Oracle in uppercase. Fields in the models may be lower case for compatibility with other databases. Match them up with the fields using the column mapping.

func New

func New(config Config) gorm.Dialector

New creates a new Dialector with the given config

func OnConflictClauseBuilder

func OnConflictClauseBuilder(c clause.Clause, builder clause.Builder)

OnConflictClauseBuilder builds MERGE statement directly

func Open

func Open(dsn string) gorm.Dialector

Open creates a new godror Dialector with the given DSN

func OracleClauseBuilders

func OracleClauseBuilders() map[string]clause.ClauseBuilder

Returns the clause builders that are used to generate clauses for Oracle DB

func QuoteIdentifier added in v0.2.0

func QuoteIdentifier(identifier string) string

func ReturningClauseBuilder

func ReturningClauseBuilder(c clause.Clause, builder clause.Builder)

Enhanced ReturningClauseBuilder that handles both RETURNING and INTO

func ShouldUseRealConflict

func ShouldUseRealConflict(values clause.Values, onConflict clause.OnConflict, conflictColumns []clause.Column) bool

Helper method to determine if we need MERGE

func Update

func Update(db *gorm.DB)

Update overrides GORM's update callback for Oracle.

It builds Oracle-compatible UPDATE statements and supports:

  • Standard updates without RETURNING using GORM’s default SQL build, with bind variable conversion for Oracle types.
  • Updates with RETURNING, emitting a PL/SQL block that performs UPDATE … RETURNING BULK COLLECT INTO for multi-row updates, wiring sql.Out binds for each returned column and row.
  • UPDATE safety: checks for missing WHERE conditions and refuses to run unless AllowGlobalUpdate is set or the WHERE clause has meaningful conditions (beyond soft-delete filters).
  • Primary key WHERE injection when the destination object or slice has identifiable PK values, to avoid unintended mass updates.
  • Soft-delete compatibility: conditions on deleted_at are ignored for the safety check, but preserved in the WHERE for the actual SQL.

For updates with RETURNING, OUT bind results are mapped back into the destination struct or slice using getUpdateReturningValues.

Register with:

db.Callback().Update().Replace("gorm:update", oracle.Update)

func UpdateClauseBuilder

func UpdateClauseBuilder(c clause.Clause, builder clause.Builder)

UpdateClauseBuilder builds the UPDATE clause

func ValuesClauseBuilder

func ValuesClauseBuilder(c clause.Clause, builder clause.Builder)

ValuesClauseBuilder builds the VALUES clause of an INSERT statement

Types

type Config

type Config struct {
	DriverName           string
	DataSourceName       string
	Conn                 *sql.DB
	DefaultStringSize    uint
	SkipQuoteIdentifiers bool
}

type Dialector

type Dialector struct {
	*Config
}

func (Dialector) BindVarTo

func (d Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{})

Handles variable binding in SQL statements

func (Dialector) DataTypeOf

func (d Dialector) DataTypeOf(field *schema.Field) string

Determines the data type for a schema field

func (Dialector) DefaultValueOf

func (d Dialector) DefaultValueOf(field *schema.Field) clause.Expression

func (Dialector) Explain

func (d Dialector) Explain(sqlStr string, vars ...interface{}) string

Explain Formats SQL statements with variables, string literals will be encoded with in ”

func (Dialector) Initialize

func (d Dialector) Initialize(db *gorm.DB) (err error)

Initializes the database connection

func (Dialector) Migrator

func (d Dialector) Migrator(db *gorm.DB) gorm.Migrator

Migrator returns the migrator instance associated with the given gorm.DB

func (Dialector) Name

func (d Dialector) Name() string

Name returns the name of the database dialect

func (Dialector) QuoteTo

func (d Dialector) QuoteTo(writer clause.Writer, str string)

Manages quoting of identifiers

func (Dialector) RollbackTo

func (d Dialector) RollbackTo(tx *gorm.DB, name string) error

RollbackTo Rolls back to the given save point

func (Dialector) SavePoint

func (d Dialector) SavePoint(tx *gorm.DB, name string) error

SavePoint creates a save point with the given name

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) AddColumn

func (m Migrator) AddColumn(value interface{}, name string) error

AddColumn creates `name` column for the given `value`

func (Migrator) AlterColumn

func (m Migrator) AlterColumn(value interface{}, field string) error

AlterColumn alters value's `field` column's type based on schema definition

func (Migrator) ColumnTypes

func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error)

ColumnTypes returns the column types for the given value’s table and any error encountered during execution

func (Migrator) CreateConstraint added in v0.2.0

func (m Migrator) CreateConstraint(value interface{}, name string) error

CreateConstraint creates constraint based on the given 'value' and 'name'

func (Migrator) CreateTable

func (m Migrator) CreateTable(values ...interface{}) error

CreateTable creates table in database for the given `values`

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() string

CurrentDatabase returns the the name of the current Oracle database

func (Migrator) DropColumn

func (m Migrator) DropColumn(value interface{}, name string) error

DropColumn drops value's `name` column

func (Migrator) DropConstraint added in v0.2.0

func (m Migrator) DropConstraint(value interface{}, name string) error

DropConstraint drops constraint based on the given 'value' and 'name'

func (Migrator) DropIndex

func (m Migrator) DropIndex(value interface{}, name string) error

DropIndex drops the index with the specified `name` from the table associated with `value`

func (Migrator) DropTable

func (m Migrator) DropTable(values ...interface{}) error

DropTable drops the table starting from the bottom of the dependency chain. The function returns an error when Oracle databases report a missing table. If multiple errors occur, it returns a combined (joint) error.

func (Migrator) FkTriggerName added in v0.2.0

func (m Migrator) FkTriggerName(refTable string, refField string, table string, field string) string

func (Migrator) FullDataTypeOf

func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr)

func (Migrator) GetTables

func (m Migrator) GetTables() (tableList []string, err error)

GetTables returns tables

func (Migrator) HasColumn

func (m Migrator) HasColumn(value interface{}, field string) bool

HasColumn checks whether the table for the given value contains the specified column `field`

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value interface{}, name string) bool

HasConstraint checks whether the table for the given `value` contains the specified constraint `name`

func (Migrator) HasIndex

func (m Migrator) HasIndex(value interface{}, name string) bool

HasIndex checks whether the table for the given `value` contains an index with the specified `name`

func (Migrator) HasTable

func (m Migrator) HasTable(value interface{}) bool

HasTable returns table exists or not for value, value could be a struct or string

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error

RenameIndex renames index from oldName to newName on the table for the given `value`

func (Migrator) RenameTable

func (m Migrator) RenameTable(oldName, newName interface{}) error

RenameTable renames table from oldName to newName

func (Migrator) RunWithValue

func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error) error

RunWithValue runs migration for the given `value`

Jump to

Keyboard shortcuts

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