CUBRID database driver for GORM.
flowchart TD
A[Application] --> B[GORM]
B --> C[gorm-cubrid Dialector]
C --> D[cubrid-go database/sql]
D --> E[CUBRID Server]
- Go 1.21+
- CUBRID 10.2+ database server
go get github.com/cubrid-labs/gorm-cubridThe CUBRID Go SQL driver must also be installed:
go get github.com/cubrid-labs/cubrid-gocubrid-go is a pure Go driver — no CGO or native libraries required.
package main
import (
_ "github.com/cubrid-labs/cubrid-go" // register CUBRID SQL driver
cubrid "github.com/cubrid-labs/gorm-cubrid"
"gorm.io/gorm"
)
func main() {
// DSN format: cubrid://[user[:password]]@host[:port]/database[?autocommit=true&timeout=30s]
dsn := "cubrid://public:@localhost:33000/demodb"
db, err := gorm.Open(cubrid.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
// AutoMigrate example
type Product struct {
gorm.Model
Name string
Price float64
}
db.AutoMigrate(&Product{})
}db, err := gorm.Open(cubrid.New(cubrid.Config{
DSN: "cubrid://public:@localhost:33000/demodb",
DefaultStringSize: 512, // default VARCHAR size (default: 256)
}), &gorm.Config{})import "database/sql"
sqlDB, err := sql.Open("cubrid", "cubrid://public:@localhost:33000/demodb")
if err != nil {
panic(err)
}
db, err := gorm.Open(cubrid.New(cubrid.Config{Conn: sqlDB}), &gorm.Config{})| Go / GORM Type | CUBRID Type |
|---|---|
bool |
TINYINT(1) |
int8, uint8 |
TINYINT |
int16, uint16 |
SMALLINT |
int32, uint32 |
INT |
int64, uint64 |
BIGINT |
float32 |
FLOAT |
float64 |
DOUBLE |
float with precision |
NUMERIC(p, s) |
string (size < 65536) |
VARCHAR(n) |
string (size ≥ 65536) |
CLOB |
time.Time |
DATETIME |
[]byte |
BLOB |
cubrid://[user[:password]]@host[:port]/database[?autocommit=true&timeout=30s]
| Field | Description | Example |
|---|---|---|
host |
CUBRID server hostname or IP (required) | localhost |
port |
CUBRID broker port (default: 33000) | 33000 |
database |
Database name (required) | demodb |
user |
Database user (optional) | public |
password |
User password (optional) | `` |
Example:
cubrid://dba:password@localhost:33000/demodb
AutoMigrate— create and alter tables automaticallyCreateTable/DropTableHasTable/HasColumn/HasIndexGetTables/ColumnTypes- Standard GORM CRUD operations
- Associations (HasOne, HasMany, BelongsTo, ManyToMany)
- Transactions
- Hooks
Basic usage:
type User struct {
ID uint
Name string
}
type Product struct {
ID uint
Name string
Price float64
}
if err := db.AutoMigrate(&User{}, &Product{}); err != nil {
panic(err)
}Best practices and CUBRID-specific notes:
- Treat
boolas an integer-backed type (SMALLINTsemantics; emitted asTINYINT(1)), because CUBRID has no nativeBOOLEANtype. - CUBRID has no native JSON type. Store JSON payloads as
VARCHAR/CLOBand validate in the application layer. - CUBRID DDL statements auto-commit. Schema changes from
AutoMigratecannot be rolled back inside a transaction. - Keep index definitions explicit (
gorm:"index",gorm:"uniqueIndex") and review generated indexes for large tables before production rollout. AutoMigratehandles table creation and additive changes well, but complex column type changes and someALTER TABLEpatterns may require manual SQL.- For production-critical systems, prefer versioned/manual migration files (or a dedicated migration tool) for deterministic review and rollback planning.
GORM soft delete works with CUBRID when a model includes gorm.DeletedAt.
import "gorm.io/gorm"
type User struct {
ID uint
Name string
DeletedAt gorm.DeletedAt `gorm:"index"`
}
// Soft delete: sets deleted_at instead of physical delete.
db.Delete(&user)
// Normal queries automatically exclude rows where deleted_at is not NULL.
var users []User
db.Find(&users)
// Include soft-deleted rows.
db.Unscoped().Find(&users)
// Permanently delete rows.
db.Unscoped().Delete(&user)Notes:
- This works because CUBRID supports
DATETIMEcolumns andWHERE ... IS NULLfilters used by GORM soft delete. - Soft delete in GORM is application-level behavior (query/update conventions), not a database-native soft-delete feature.
- CUBRID does not support unsigned integer types.
uintfields are mapped to their signed equivalents of the next larger size. - Schema introspection (
HasTable,HasColumn,ColumnTypes, etc.) requiresINFORMATION_SCHEMAsupport, available in CUBRID 11.2+. AUTO_INCREMENTcolumns use CUBRID's nativeAUTO_INCREMENTattribute.
| Package | Description |
|---|---|
| cubrid-go | database/sql driver + GORM dialector |
| gorm-cubrid | GORM dialect for CUBRID (this package) |
See ROADMAP.md for this project's direction and next milestones.
For the ecosystem-wide view, see the CUBRID Labs Ecosystem Roadmap and Project Board.
MIT