+
Skip to content

tiltwind/duckdb

 
 

Repository files navigation

GORM DuckDB Driver

Go Reference Go version GitHub release Go Report Card License


Quick Start

import (
  "github.com/vogo/duckdb"
  "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.

About

gorm duckdb driver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.0%
  • Makefile 1.0%
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载