cLiEnT WAHBG JUSAGHEJWBFDRIOUASnaefhsbgktw jvskfgaehji bsšućaf
This commit is contained in:
@@ -14,13 +14,13 @@ import (
|
||||
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
||||
)
|
||||
|
||||
// Client wraps ClickHouse connection and operations
|
||||
type Client struct {
|
||||
conn driver.Conn
|
||||
// ClickhouseClient wraps ClickHouse connection and operations
|
||||
type ClickhouseClient struct {
|
||||
Conn driver.Conn
|
||||
}
|
||||
|
||||
// NewClient creates a new ClickHouse client using config
|
||||
func NewClient() (*Client, error) {
|
||||
func NewClient() (*ClickhouseClient, error) {
|
||||
options := &clickhouse.Options{
|
||||
Addr: []string{config.ClickhouseHost},
|
||||
Auth: clickhouse.Auth{
|
||||
@@ -39,24 +39,24 @@ func NewClient() (*Client, error) {
|
||||
return nil, fmt.Errorf("failed to connect to ClickHouse: %w", err)
|
||||
}
|
||||
|
||||
return &Client{conn: conn}, nil
|
||||
return &ClickhouseClient{Conn: conn}, nil
|
||||
}
|
||||
|
||||
// Close closes the ClickHouse connection
|
||||
func (c *Client) Close() error {
|
||||
if c.conn != nil {
|
||||
return c.conn.Close()
|
||||
func (c *ClickhouseClient) Close() error {
|
||||
if c.Conn != nil {
|
||||
return c.Conn.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Query executes a SELECT query and returns the rows
|
||||
func (c *Client) Query(ctx context.Context, query string, args ...interface{}) (driver.Rows, error) {
|
||||
return c.conn.Query(ctx, query, args...)
|
||||
func (c *ClickhouseClient) Query(ctx context.Context, query string, args ...interface{}) (driver.Rows, error) {
|
||||
return c.Conn.Query(ctx, query, args...)
|
||||
}
|
||||
|
||||
// SaveFlatKillmails saves flattened killmails, attackers, and items to ClickHouse using JSON format
|
||||
func (c *Client) SaveFlatKillmails(
|
||||
func (c *ClickhouseClient) SaveFlatKillmails(
|
||||
killmails []*types.FlatKillmail,
|
||||
attackers []types.FlatKillmailAttacker,
|
||||
items []types.FlatKillmailItem,
|
||||
@@ -78,7 +78,7 @@ func (c *Client) SaveFlatKillmails(
|
||||
}
|
||||
|
||||
// insertKillmailsJSON inserts killmails using JSON format
|
||||
func (c *Client) insertKillmailsJSON(ctx context.Context, killmails []*types.FlatKillmail) error {
|
||||
func (c *ClickhouseClient) insertKillmailsJSON(ctx context.Context, killmails []*types.FlatKillmail) error {
|
||||
if len(killmails) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (c *Client) insertKillmailsJSON(ctx context.Context, killmails []*types.Fla
|
||||
if len(jsonRows) > 0 {
|
||||
jsonData := strings.Join(jsonRows, "\n")
|
||||
query := fmt.Sprintf("INSERT INTO zkill.killmails FORMAT JSONEachRow\n%s", jsonData)
|
||||
if err := c.conn.Exec(ctx, query); err != nil {
|
||||
if err := c.Conn.Exec(ctx, query); err != nil {
|
||||
batchErrors = append(batchErrors, fmt.Errorf("failed to insert killmails batch: %w", err))
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (c *Client) insertKillmailsJSON(ctx context.Context, killmails []*types.Fla
|
||||
}
|
||||
|
||||
// insertAttackersJSON inserts attackers using JSON format
|
||||
func (c *Client) insertAttackersJSON(ctx context.Context, attackers []types.FlatKillmailAttacker) error {
|
||||
func (c *ClickhouseClient) insertAttackersJSON(ctx context.Context, attackers []types.FlatKillmailAttacker) error {
|
||||
if len(attackers) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (c *Client) insertAttackersJSON(ctx context.Context, attackers []types.Flat
|
||||
if len(jsonRows) > 0 {
|
||||
jsonData := strings.Join(jsonRows, "\n")
|
||||
query := fmt.Sprintf("INSERT INTO zkill.killmail_attackers FORMAT JSONEachRow\n%s", jsonData)
|
||||
if err := c.conn.Exec(ctx, query); err != nil {
|
||||
if err := c.Conn.Exec(ctx, query); err != nil {
|
||||
batchErrors = append(batchErrors, fmt.Errorf("failed to insert attackers batch: %w", err))
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (c *Client) insertAttackersJSON(ctx context.Context, attackers []types.Flat
|
||||
}
|
||||
|
||||
// insertItemsJSON inserts items using JSON format
|
||||
func (c *Client) insertItemsJSON(ctx context.Context, items []types.FlatKillmailItem) error {
|
||||
func (c *ClickhouseClient) insertItemsJSON(ctx context.Context, items []types.FlatKillmailItem) error {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (c *Client) insertItemsJSON(ctx context.Context, items []types.FlatKillmail
|
||||
if len(jsonRows) > 0 {
|
||||
jsonData := strings.Join(jsonRows, "\n")
|
||||
query := fmt.Sprintf("INSERT INTO zkill.killmail_items FORMAT JSONEachRow\n%s", jsonData)
|
||||
if err := c.conn.Exec(ctx, query); err != nil {
|
||||
if err := c.Conn.Exec(ctx, query); err != nil {
|
||||
batchErrors = append(batchErrors, fmt.Errorf("failed to insert items batch: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user