initial hasql support #407
@@ -3,20 +3,12 @@ package sql
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.yandex/hasql/v2"
|
"golang.yandex/hasql/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrClusterChecker = errors.New("cluster node checker required")
|
|
||||||
ErrClusterDiscoverer = errors.New("cluster node discoverer required")
|
|
||||||
ErrClusterPicker = errors.New("cluster node picker required")
|
|
||||||
ErrorNoAliveNodes = errors.New("cluster no alive nodes")
|
|
||||||
)
|
|
||||||
|
|
||||||
func newSQLRowError() *sql.Row {
|
func newSQLRowError() *sql.Row {
|
||||||
row := &sql.Row{}
|
row := &sql.Row{}
|
||||||
t := reflect.TypeOf(row).Elem()
|
t := reflect.TypeOf(row).Elem()
|
||||||
@@ -33,25 +25,6 @@ type ClusterQuerier interface {
|
|||||||
WaitForNodes(ctx context.Context, criterion ...hasql.NodeStateCriterion) error
|
WaitForNodes(ctx context.Context, criterion ...hasql.NodeStateCriterion) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Querier interface {
|
|
||||||
// Basic connection methods
|
|
||||||
PingContext(ctx context.Context) error
|
|
||||||
Close() error
|
|
||||||
|
|
||||||
// Query methods with context
|
|
||||||
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
|
||||||
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
|
||||||
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
|
|
||||||
|
|
||||||
// Prepared statements with context
|
|
||||||
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
|
|
||||||
|
|
||||||
// Transaction management with context
|
|
||||||
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
|
|
||||||
|
|
||||||
Conn(ctx context.Context) (*sql.Conn, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
hasql *hasql.Cluster[Querier]
|
hasql *hasql.Cluster[Querier]
|
||||||
options ClusterOptions
|
options ClusterOptions
|
||||||
|
25
cluster/hasql/db.go
Normal file
25
cluster/hasql/db.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package sql
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Querier interface {
|
||||||
|
// Basic connection methods
|
||||||
|
PingContext(ctx context.Context) error
|
||||||
|
Close() error
|
||||||
|
|
||||||
|
// Query methods with context
|
||||||
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
||||||
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
||||||
|
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
|
||||||
|
|
||||||
|
// Prepared statements with context
|
||||||
|
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
|
||||||
|
|
||||||
|
// Transaction management with context
|
||||||
|
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
|
||||||
|
|
||||||
|
Conn(ctx context.Context) (*sql.Conn, error)
|
||||||
|
}
|
@@ -119,7 +119,7 @@ func TestDriver(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := OpenDBWithDriver(c)
|
db, err := OpenDBWithCluster(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
10
cluster/hasql/error.go
Normal file
10
cluster/hasql/error.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package sql
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrClusterChecker = errors.New("cluster node checker required")
|
||||||
|
ErrClusterDiscoverer = errors.New("cluster node discoverer required")
|
||||||
|
ErrClusterPicker = errors.New("cluster node picker required")
|
||||||
|
ErrorNoAliveNodes = errors.New("cluster no alive nodes")
|
||||||
|
)
|
Reference in New Issue
Block a user