|
@@ -6,13 +6,12 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/ClickHouse/clickhouse-go/v2"
|
|
|
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type _ch struct {
|
|
|
- Database[driver.Rows, driver.Batch]
|
|
|
-
|
|
|
config *configCH
|
|
|
conn clickhouse.Conn
|
|
|
}
|
|
@@ -84,6 +83,37 @@ func (db *_ch) Ping(ctx context.Context) error {
|
|
|
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) {
|
|
|
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
|
|
|
+}
|