Categorygithub.com/Trendyol/go-dcp-sql
modulepackage
0.0.0-20250125132652-1e18691040ea
Repository: https://github.com/trendyol/go-dcp-sql.git
Documentation: pkg.go.dev

# README

Go Dcp SQL

Go Reference Go Report Card OpenSSF Scorecard

Go Dcp SQL streams documents from Couchbase Database Change Protocol (DCP) and writes to SQL tables in near real-time.

Features

  • Custom SQL queries per DCP event.
  • Update multiple documents for a DCP event(see Example).
  • Handling different DCP events such as expiration, deletion and mutation(see Example).
  • Managing batch configurations such as maximum batch size, batch ticker durations.
  • Scale up and down by custom membership algorithms(Couchbase, KubernetesHa, Kubernetes StatefulSet or Static, see examples).
  • Easily manageable configurations.

Example


import (
    _ "github.com/lib/pq" // DON'T FORGET TO ADD THE DRIVER
)
func mapper(event couchbase.Event) []sql.Model {
    var raw = sql.Raw{
        Query: fmt.Sprintf(
            "INSERT INTO `example-schema`.`example-table` (key, value) VALUES ('%s', '%s')",
            string(event.Key),
            string(event.Value),
        ),
    }
    return []sql.Model{&raw}
}

func main() {
    connector, err := dcpsql.NewConnectorBuilder("config.yml").
    SetMapper(mapper).Build()
	
    if err != nil {
        panic(err)
    }
    
    defer connector.Close()
    connector.Start()
}

Configuration

Dcp Configuration

Check out on go-dcp

SQL Specific Configuration

VariableTypeRequiredDefaultDescription
sql.hoststringyesSQL connection urls
sql.userstringyesSQL username
sql.passwordstringyesSQL password
sql.dbNamestringyes1000SQL database name
sql.sslModestringnodisableEnabling SQL SSL mode
sql.driverNamestringyesDriver name
sql.portintyesSQL port
sql.batchSizeLimitintno1000Maximum message count for batch, if exceed flush will be triggered
sql.batchTickerDurationtime.Durationno10sBatch is being flushed automatically at specific time intervals for long waiting messages in batch

Exposed metrics

Metric NameDescriptionLabelsValue Type
sql_connector_latency_msTime to adding to the batch.N/AGauge
sql_connector_bulk_request_process_latency_msTime to process bulk request.N/AGauge

You can also use all DCP-related metrics explained here. All DCP-related metrics are automatically injected. It means you don't need to do anything.

Contributing

Go Dcp SQL is always open for direct contributions. For more information please check our Contribution Guideline document.

License

Released under the MIT License.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author