duckdb

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

GORM DuckDB Driver

Go Reference Go version GitHub release Go Report Card License


Quick Start

import (
  "github.com/hauntedness/duckdb/v2"
  "gorm.io/gorm"
)

type Product struct {
	ID        uint `gorm:"primarykey"`
	Code      string
	Price     uint
	CreatedAt time.Time
	UpdatedAt time.Time
}

func main() {
	db, err := gorm.Open(duckdb.Open("duckdb.ddb"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	db.AutoMigrate(&Product{})

	// Create
	db.Create(&Product{Code: "D42", Price: 100})

	// Read
	var product Product
	db.First(&product, 1)
	db.First(&product, "code = ?", "D42")

	// Update
	db.Model(&product).Update("Price", 200)
	db.Model(&product).Updates(Product{Price: 200, Code: "F42"})

	// Delete
	db.Delete(&product, 1)
}

Checkout https://gorm.io for details.

Limitations

deleted_at field

Do not use gorm.Model - use custom struct with ID, CreatedAt, UpdatedAt fields instead.

DuckDB's ART indexes have limitations with soft deletes. When GORM performs db.Delete(), it updates the deleted_at field instead of actually deleting the record, which can cause primary key constraint violations due to how DuckDB handles transactions and indexes.

See DuckDB documentation for details.

Contributing

Any contributions you make are greatly appreciated.

License

This project is licensed under the Apache License 2.0.

Documentation

Index

Constants

View Source
const DriverName = "duckdb"

Variables

View Source
var ErrDuckDBNotSupported = errors.New("DuckDB are not supported this operation")
View Source
var ErrInvalidAssert = errors.New("Invalid type assertion")

Functions

func New

func New(config Config) gorm.Dialector

func Open

func Open(dsn string) gorm.Dialector

Types

type BuildIndexOptionsInterface

type BuildIndexOptionsInterface interface {
	BuildIndexOptions([]schema.IndexOption, *gorm.Statement) []any
}

type Config

type Config struct {
	DriverName string
	DSN        string
	Conn       gorm.ConnPool
}

type Dialector

type Dialector struct {
	*Config
}

func (Dialector) BindVarTo

func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v any)

func (Dialector) ClauseBuilders

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

func (Dialector) DataTypeOf

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

func (Dialector) DefaultValueOf

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

func (Dialector) Explain

func (dialector Dialector) Explain(sql string, vars ...any) string

func (Dialector) Initialize

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

func (Dialector) Migrator

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

func (Dialector) Name

func (dialector Dialector) Name() string

func (Dialector) QuoteTo

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

func (Dialector) RollbackTo

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

func (Dialector) SavePoint

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

func (Dialector) SupportReturning

func (dialector Dialector) SupportReturning() bool

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) CreateIndex

func (m Migrator) CreateIndex(value any, name string) error

func (Migrator) CreateTable

func (m Migrator) CreateTable(values ...any) (err error)

func (Migrator) CreateView

func (m Migrator) CreateView(name string, option gorm.ViewOption) error

Views.

func (Migrator) CurrentDatabase

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

func (Migrator) CurrentSchema

func (m Migrator) CurrentSchema(stmt *gorm.Statement, table string) (any, any)

func (Migrator) DropColumn

func (m Migrator) DropColumn(dst any, field string) error

Columns.

func (Migrator) DropIndex

func (m Migrator) DropIndex(value any, name string) error

func (Migrator) DropTable

func (m Migrator) DropTable(values ...any) error

func (Migrator) DropView

func (m Migrator) DropView(name string) error

func (Migrator) FullDataTypeOf

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

func (Migrator) GetTables

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

func (Migrator) GetTypeAliases

func (m Migrator) GetTypeAliases(databaseTypeName string) []string

func (Migrator) HasColumn

func (m Migrator) HasColumn(value any, field string) bool

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value any, name string) bool

func (Migrator) HasIndex

func (m Migrator) HasIndex(value any, name string) bool

func (Migrator) HasTable

func (m Migrator) HasTable(value any) bool

func (Migrator) MigrateColumn

func (m Migrator) MigrateColumn(value any, field *schema.Field, columnType gorm.ColumnType) error

func (Migrator) RenameColumn

func (m Migrator) RenameColumn(dst any, oldName, field string) error

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(dst any, oldName, newName string) error

func (Migrator) RenameTable

func (m Migrator) RenameTable(oldName, newName any) (err error)

Jump to

Keyboard shortcuts

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