Alexey Kim 1 жил өмнө
parent
commit
22844bb93a

+ 2 - 8
connection/cursor.go

@@ -1,16 +1,10 @@
 package connection
 package connection
 
 
+type Namespace string
+
 type Cursor interface {
 type Cursor interface {
 	NS() Namespace
 	NS() Namespace
 	Id() string
 	Id() string
 
 
 	Cursor() string
 	Cursor() string
 }
 }
-
-type Namespace string
-
-const (
-	NSMatch  Namespace = "Match"
-	NSLeague Namespace = "League"
-	NSTeam   Namespace = "Team"
-)

+ 32 - 2
database/clickhouse.go

@@ -6,13 +6,12 @@ import (
 	"fmt"
 	"fmt"
 	"github.com/ClickHouse/clickhouse-go/v2"
 	"github.com/ClickHouse/clickhouse-go/v2"
 	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
 	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
+	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 )
 )
 
 
 type _ch struct {
 type _ch struct {
-	Database[driver.Rows, driver.Batch]
-
 	config *configCH
 	config *configCH
 	conn   clickhouse.Conn
 	conn   clickhouse.Conn
 }
 }
@@ -84,6 +83,37 @@ func (db *_ch) Ping(ctx context.Context) error {
 	return db.conn.Ping(ctx)
 	return db.conn.Ping(ctx)
 }
 }
 
 
+func (db *_ch) Exec(ctx context.Context, query string, args ...any) error {
+	return db.conn.Exec(ctx, query, args...)
+}
+
 func (db *_ch) Query(ctx context.Context, query string, args ...any) (driver.Rows, error) {
 func (db *_ch) Query(ctx context.Context, query string, args ...any) (driver.Rows, error) {
 	return db.conn.Query(ctx, query, args...)
 	return db.conn.Query(ctx, query, args...)
 }
 }
+
+func (db *_ch) Batch(ctx context.Context, table string, release bool) (driver.Batch, error) {
+	table = strings.TrimSpace(table)
+	if table == "" {
+		return nil, fmt.Errorf("illegal argumets: empty table name")
+	}
+
+	var (
+		batch driver.Batch
+		opts  []driver.PrepareBatchOption
+		err   error
+	)
+
+	if release {
+		opts = append(opts, driver.WithReleaseConnection())
+	}
+
+	if //goland:noinspection SqlNoDataSourceInspection
+	batch, err = db.conn.PrepareBatch(ctx,
+		fmt.Sprintf("INSERT INTO `%s`", table),
+		opts...,
+	); err != nil {
+		return nil, err
+	}
+
+	return batch, nil
+}

+ 1 - 0
database/database.go

@@ -9,6 +9,7 @@ type Database[T any, B any] interface {
 	Close() error
 	Close() error
 
 
 	Ping(ctx context.Context) error
 	Ping(ctx context.Context) error
+	Exec(ctx context.Context, query string, args ...any) error
 	Query(ctx context.Context, query string, args ...any) (T, error)
 	Query(ctx context.Context, query string, args ...any) (T, error)
 	Batch(ctx context.Context, table string, release bool) (B, error)
 	Batch(ctx context.Context, table string, release bool) (B, error)
 }
 }