# README
sql
Connect (Single)
const connectionString = "host=localhost port=5432 user=dbuser password=qwerty dbname=testdb sslmode=disable"
conn := sql.MustConnect(connectionString)
defer conn.Close() // or life.Tear(conn.Close)
rows, err := conn.QueryxContext(context.Background(), "SELECT * FROM users")
// ...
Connect (Shard)
connectionStrings := []sql.ShardConnectString{
{
Name: "shard1",
ConnectionString: "host=localhost port=5432 user=dbuser password=qwerty dbname=testdb sslmode=disable",
},
{
Name: "shard2",
ConnectionString: "host=localhost port=5433 user=dbuser password=qwerty dbname=testdb sslmode=disable",
},
}
connections := sql.MustConnectShards(connectionStrings, func(ctx context.Context, connections []sql.ShardConnect) sql.ShardConnect {
// select connection by context value by key "shard"
shard := to.String(ctx.Value("shard"))
for _, conn := range connections {
// if connection name equals to context "shard" value, return connection
if conn.Name() == shard {
return conn
}
}
return nil
})
defer connections.Close() // or life.Tear(connections.Close)
client := sql.ClientShard(connections)
rows, err := client.QueryxContext(getShardContext("shard1"), "SELECT * FROM users")
// ...
# Functions
No description provided by the author
BackgroundMigrate calls Migrate function and if error catch print log.
Client creates DB implementation by single client.
ClientShard creates DB implementation as shard client.
Connect to the database.
ConnectShards connect all provided connections and create Connections object.
EachShard runs provided fn function with every shard single connection.
EachShardAsync do the same as EachShard but in parallel every shard.
GetTx returns sql transaction object from context if it exist.
Migrate runs migration by provided connection & database name.
MustConnect calls Connect and if err catch throws panic.
MustConnectShards calls ConnectShards and if error catch throws panic.
MustMigrate calls Migrate function and if error catch throws panic.
NewArguments created instance of Arguments object.
NewConnector creates Connector object.
NewTransactor creates SQL transactor.
NotFound check if provided error is not found error.
Page returns offset & limit by pagination.
SetTx sets transaction key to new context.
Transaction run "actions" by created transaction object.
# Structs
Arguments Helps manage query arguments count & their values.
Connections contain all connections for shard client and selector for choosing connection.
Connector helper for creating connection.
No description provided by the author
# Interfaces
DB description of all methods of sqlx package.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ShardConnect contain connection & it's key for shard client.
TransactorConnectionProvider sql transaction interface.