oracle

package module
v0.0.0-...-7edb066 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 21 Imported by: 0

README

GORM Oracle driver

Description

GORM-ORACLE is a GORM driver that does not depend on the Oracle client, Based on github.com/CengSin/oracle , not thoroughly tested and not recommended for production use.

项目集成go-ora驱动,无需安装oracle客户端。

DB Driver

go-ora A pure golang development of Oracle driver, do not need to install Oracle client.

Quick Start

how to install
go get github.com/wdrabbit/gorm-oracle
usage
import (
    "gorm.io/gorm"
    "oracle "github.com/wdrabbit/gorm-oracle"
    "log"
)

//ORM bean
type TestBean struct {
	Id string `gorm:"column:ID;not null;primaryKey;size:36"`
	Field1 string `gorm:"column:FIELD1;size:255"`
	Field2 string `gorm:"column:FIELD2;size:255"`
	State string `gorm:"column:STATE;size:2"`
	CreateAt time.Time `gorm:"column:CREATE_AT"`
}

func main(){

    databaseURL := "oracle://username:password@host:port/db"
    db, err := gorm.Open(oracle.Open(databaseURL),&gorm.Config{})
    if err != nil {
        log.Fatal(err)
    }
    
    //Insert
    datas := []bean.TestBean{
        {"a","a","a","01",time.Now()},
        {"b","a","a","01",time.Now()},
    }
    db = db.Debug().Create(&datas)

    //Update
    db = db.Debug().Where("id=?","a").Model(&bean.TestBean{}).Update("state","02")

    //Delete
    db := db.Where("id = ?","a").Delete(&bean.TestBean{})

    //Select
    var rows []bean.TestBean
    db = db.Debug().Find(&rows)
    
    //do somethings

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReservedWords = hashset.New(funk.Map(ReservedWordsList, func(s string) interface{} { return s }).([]interface{})...)
View Source
var ReservedWordsList = []string{}/* 142 elements not displayed */

Functions

func Create

func Create(db *gorm.DB)

func IsReservedWord

func IsReservedWord(v string) bool

func New

func New(config Config) gorm.Dialector

func Open

func Open(dsn string) gorm.Dialector

Types

type Config

type Config struct {
	DriverName        string
	DSN               string
	Conn              *sql.DB
	DefaultStringSize uint
}

type Dialector

type Dialector struct {
	*Config
}

func (Dialector) BindVarTo

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

func (Dialector) ClauseBuilders

func (d Dialector) ClauseBuilders() map[string]clause.ClauseBuilder

func (Dialector) DataTypeOf

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

func (Dialector) DefaultValueOf

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

func (Dialector) DummyTableName

func (d Dialector) DummyTableName() string

func (Dialector) Explain

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

func (Dialector) Initialize

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

func (Dialector) Migrator

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

func (Dialector) Name

func (d Dialector) Name() string

func (Dialector) QuoteTo

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

func (Dialector) RewriteLimit

func (d Dialector) RewriteLimit(c clause.Clause, builder clause.Builder)

func (Dialector) RewriteWhere

func (d Dialector) RewriteWhere(c clause.Clause, builder clause.Builder)

func (Dialector) RollbackTo

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

func (Dialector) SavePoint

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

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) AddColumn

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

func (Migrator) AlterColumn

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

func (Migrator) CreateConstraint

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

func (Migrator) CreateTable

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

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() (name string)

func (Migrator) DropColumn

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

func (Migrator) DropConstraint

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

func (Migrator) DropIndex

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

func (Migrator) DropTable

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

func (Migrator) HasColumn

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

func (Migrator) HasConstraint

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

func (Migrator) HasIndex

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

func (Migrator) HasTable

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

func (Migrator) RenameIndex

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

https://docs.oracle.com/database/121/SPATL/alter-index-rename.htm

func (Migrator) RenameTable

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

func (Migrator) TryQuotifyReservedWords

func (m Migrator) TryQuotifyReservedWords(values []interface{}) error

func (Migrator) TryRemoveOnUpdate

func (m Migrator) TryRemoveOnUpdate(value interface{}) error

type Namer

type Namer interface {
	TableName(table string) string
	SchemaName(table string) string
	ColumnName(table, column string) string
	JoinTableName(joinTable string) string
	RelationshipFKName(schema.Relationship) string
	CheckerName(table, column string) string
	IndexName(table, column string) string
}

Namer namer interface

type NamingStrategy

type NamingStrategy struct {
	TablePrefix   string
	SingularTable bool
	NameReplacer  Replacer
	NoLowerCase   bool
}

NamingStrategy tables, columns naming strategy

func (NamingStrategy) CheckerName

func (ns NamingStrategy) CheckerName(table, column string) string

CheckerName generate checker name

func (NamingStrategy) ColumnName

func (ns NamingStrategy) ColumnName(table, column string) string

ColumnName convert string to column name

func (NamingStrategy) IndexName

func (ns NamingStrategy) IndexName(table, column string) string

IndexName generate index name

func (NamingStrategy) JoinTableName

func (ns NamingStrategy) JoinTableName(str string) string

JoinTableName convert string to join table name

func (NamingStrategy) RelationshipFKName

func (ns NamingStrategy) RelationshipFKName(rel schema.Relationship) string

RelationshipFKName generate fk name for relation

func (NamingStrategy) SchemaName

func (ns NamingStrategy) SchemaName(table string) string

SchemaName generate schema name from table name, don't guarantee it is the reverse value of TableName

func (NamingStrategy) TableName

func (ns NamingStrategy) TableName(str string) string

TableName convert string to table name

func (NamingStrategy) UniqueName

func (ns NamingStrategy) UniqueName(table string, column string) string

type Replacer

type Replacer interface {
	Replace(name string) string
}

Replacer replacer interface like strings.Replacer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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