{"modulePath":"github.com/GhostChild/krts","version":"v0.6.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sql\n\n## Variables\n\n```go\nvar (\n\t// ErrStmtNil prepared stmt error\n\tErrStmtNil = errors.New(\"sql: prepare failed and stmt nil\")\n\t// ErrNoMaster is returned by Master when call master multiple times.\n\tErrNoMaster = errors.New(\"sql: no master instance\")\n\t// ErrNoRows is returned by Scan when QueryRow doesn't return a row.\n\t// In such a case, QueryRow returns a placeholder *Row value that defers\n\t// this error until a Scan.\n\tErrNoRows = sql.ErrNoRows\n\t// ErrTxDone transaction done.\n\tErrTxDone = sql.ErrTxDone\n)\n```\n\n## Types\n\n```go\ntype Config struct {\n\tDSN          string          // write data source name.\n\tReadDSN      []string        // read data source name.\n\tActive       int             // pool\n\tIdle         int             // pool\n\tIdleTimeout  time.Duration   // connect max life time.\n\tQueryTimeout time.Duration   // query sql timeout\n\tExecTimeout  time.Duration   // execute sql timeout\n\tTranTimeout  time.Duration   // transaction sql timeout\n\tBreaker      *breaker.Config // breaker\n}\n```\nConfig mysql config.\n\n```go\ntype DB struct {\n\t// contains filtered or unexported fields\n}\n```\nDB database.\n\n```go\nfunc NewMySQL(c *Config) (db *DB)\n```\nNewMySQL new db and retry connection when has error.\n\n```go\nfunc Open(c *Config) (*DB, error)\n```\nOpen opens a database specified by its database driver name and a driver-specific data source name, usually consisting of at least a database name and connection information.\n\n```go\nfunc (db *DB) Begin(c context.Context) (tx *Tx, err error)\n```\nBegin starts a transaction. The isolation level is dependent on the driver.\n\n```go\nfunc (db *DB) Close() (err error)\n```\nClose closes the write and read database, releasing any open resources.\n\n```go\nfunc (db *DB) Exec(c context.Context, query string, args ...interface{}) (res sql.Result, err error)\n```\nExec executes a query without returning any rows. The args are for any placeholder parameters in the query.\n\n```go\nfunc (db *DB) Master() *DB\n```\nMaster return \\*DB instance direct use master conn use this \\*DB instance only when you have some reason need to get result without any delay.\n\n```go\nfunc (db *DB) Ping(c context.Context) (err error)\n```\nPing verifies a connection to the database is still alive, establishing a connection if necessary.\n\n```go\nfunc (db *DB) Prepare(query string) (*Stmt, error)\n```\nPrepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.\n\n```go\nfunc (db *DB) Prepared(query string) (stmt *Stmt)\n```\nPrepared creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.\n\n```go\nfunc (db *DB) Query(c context.Context, query string, args ...interface{}) (rows *Rows, err error)\n```\nQuery executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.\n\n```go\nfunc (db *DB) QueryRow(c context.Context, query string, args ...interface{}) *Row\n```\nQueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called.\n\n```go\ntype Row struct {\n\t*sql.Row\n\t// contains filtered or unexported fields\n}\n```\nRow row.\n\n```go\nfunc (r *Row) Scan(dest ...interface{}) (err error)\n```\nScan copies the columns from the matched row into the values pointed at by dest.\n\n```go\ntype Rows struct {\n\t*sql.Rows\n\t// contains filtered or unexported fields\n}\n```\nRows rows.\n\n```go\nfunc (rs *Rows) Close() (err error)\n```\nClose closes the Rows, preventing further enumeration. If Next is called and returns false and there are no further result sets, the Rows are closed automatically and it will suffice to check the result of Err. Close is idempotent and does not affect the result of Err.\n\n```go\ntype Stmt struct {\n\t// contains filtered or unexported fields\n}\n```\nStmt prepared stmt.\n\n```go\nfunc (s *Stmt) Close() (err error)\n```\nClose closes the statement.\n\n```go\nfunc (s *Stmt) Exec(c context.Context, args ...interface{}) (res sql.Result, err error)\n```\nExec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.\n\n```go\nfunc (s *Stmt) Query(c context.Context, args ...interface{}) (rows *Rows, err error)\n```\nQuery executes a prepared query statement with the given arguments and returns the query results as a \\*Rows.\n\n```go\nfunc (s *Stmt) QueryRow(c context.Context, args ...interface{}) (row *Row)\n```\nQueryRow executes a prepared query statement with the given arguments. If an error occurs during the execution of the statement, that error will be returned by a call to Scan on the returned \\*Row, which is always non-nil. If the query selects no rows, the \\*Row's Scan will return ErrNoRows. Otherwise, the \\*Row's Scan scans the first selected row and discards the rest.\n\n```go\ntype Tx struct {\n\t// contains filtered or unexported fields\n}\n```\nTx transaction.\n\n```go\nfunc (tx *Tx) Commit() (err error)\n```\nCommit commits the transaction.\n\n```go\nfunc (tx *Tx) Exec(query string, args ...interface{}) (res sql.Result, err error)\n```\nExec executes a query that doesn't return rows. For example: an INSERT and UPDATE.\n\n```go\nfunc (tx *Tx) Prepare(query string) (*Stmt, error)\n```\nPrepare creates a prepared statement for use within a transaction. The returned statement operates within the transaction and can no longer be used once the transaction has been committed or rolled back. To use an existing prepared statement on this transaction, see Tx.Stmt.\n\n```go\nfunc (tx *Tx) Query(query string, args ...interface{}) (rows *Rows, err error)\n```\nQuery executes a query that returns rows, typically a SELECT.\n\n```go\nfunc (tx *Tx) QueryRow(query string, args ...interface{}) *Row\n```\nQueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called.\n\n```go\nfunc (tx *Tx) Rollback() (err error)\n```\nRollback aborts the transaction.\n\n```go\nfunc (tx *Tx) Stmt(stmt *Stmt) *Stmt\n```\nStmt returns a transaction-specific prepared statement from an existing statement.\n\n","path":"github.com/GhostChild/krts/pkg/database/sql","name":"sql","synopsis":"","isRedistributable":true}
