Add datastore database driver for Hanzo Datastore

Registers "datastore://" as a URL scheme that delegates to the
ClickHouse driver. This allows golang-migrate to natively connect
to Hanzo Datastore instances without URL rewriting in scripts.
This commit is contained in:
Zach Kelling
2026-03-03 09:15:21 -08:00
parent 257fa847d6
commit 837dda3cc9
4 changed files with 57 additions and 1 deletions
+1
View File
@@ -8,3 +8,4 @@ vendor/
.vscode/
.idea
dist/
migrate
+1 -1
View File
@@ -1,5 +1,5 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse datastore mongodb sqlserver firebird neo4j pgx pgx5 rqlite
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
TEST_FLAGS ?=
+47
View File
@@ -0,0 +1,47 @@
// Package datastore implements the database.Driver interface for Hanzo Datastore
// (a ClickHouse-compatible database engine). It registers the "datastore://" URL
// scheme so that golang-migrate can connect to Datastore instances natively.
//
// Usage:
//
// import _ "github.com/golang-migrate/migrate/v4/database/datastore"
//
// Then use a URL like:
//
// datastore://host:9000?username=default&database=default&x-multi-statement=true
package datastore
import (
"database/sql"
"net/url"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/clickhouse"
_ "github.com/ClickHouse/clickhouse-go"
)
func init() {
database.Register("datastore", &Datastore{})
}
// Datastore wraps the ClickHouse driver, registering under the "datastore" scheme.
type Datastore struct {
clickhouse.ClickHouse
}
// Open rewrites the "datastore://" scheme to "clickhouse://" and delegates
// to the underlying ClickHouse driver.
func (d *Datastore) Open(dsn string) (database.Driver, error) {
u, err := url.Parse(dsn)
if err != nil {
return nil, err
}
u.Scheme = "clickhouse"
return d.ClickHouse.Open(u.String())
}
// WithInstance creates a new Datastore driver from an existing sql.DB connection.
func WithInstance(conn *sql.DB, config *clickhouse.Config) (database.Driver, error) {
return clickhouse.WithInstance(conn, config)
}
+8
View File
@@ -0,0 +1,8 @@
//go:build datastore
package cli
import (
_ "github.com/ClickHouse/clickhouse-go"
_ "github.com/golang-migrate/migrate/v4/database/datastore"
)