Make all text fit sql slides
This commit is contained in:
parent
38478f189a
commit
e1cf5d8de3
7 changed files with 32 additions and 28 deletions
|
@ -1,17 +1,17 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
type DBStats struct {
|
type DBStats struct {
|
||||||
MaxOpenConnections int // Maximum number of open connections to the database; added in Go 1.11
|
MaxOpenConnections int // Maximum number of open connections to the database; added in Go 1.11
|
||||||
|
|
||||||
// Pool Status
|
// Pool Status
|
||||||
OpenConnections int // The number of established connections both in use and idle.
|
OpenConnections int // The number of established connections both in use and idle.
|
||||||
InUse int // The number of connections currently in use; added in Go 1.11
|
InUse int // The number of connections currently in use; added in Go 1.11
|
||||||
Idle int // The number of idle connections; added in Go 1.11
|
Idle int // The number of idle connections; added in Go 1.11
|
||||||
|
|
||||||
// Counters
|
// Counters
|
||||||
WaitCount int64 // The total number of connections waited for; added in Go 1.11
|
WaitCount int64 // The total number of connections waited for; added in Go 1.11
|
||||||
WaitDuration time.Duration // The total time blocked waiting for a new connection; added in Go 1.11
|
WaitDuration time.Duration // The total time blocked waiting for a new connection; added in Go 1.11
|
||||||
MaxIdleClosed int64 // The total number of connections closed due to SetMaxIdleConns; added in Go 1.11
|
MaxIdleClosed int64 // The total number of connections closed due to SetMaxIdleConns; added in Go 1.11
|
||||||
MaxIdleTimeClosed int64 // The total number of connections closed due to SetConnMaxIdleTime; added in Go 1.15
|
MaxIdleTimeClosed int64 // The total number of connections closed due to SetConnMaxIdleTime; added in Go 1.15
|
||||||
MaxLifetimeClosed int64 // The total number of connections closed due to SetConnMaxLifetime; added in Go 1.11
|
MaxLifetimeClosed int64 // The total number of connections closed due to SetConnMaxLifetime; added in Go 1.11
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Exec(ctx context.Context, db *sql.DB) {
|
func Exec(ctx context.Context, db *sql.DB) {
|
||||||
res, err := db.ExecContext(ctx, "UPDATE users SET name = $1 WHERE id = $2", "William Mandella", 1)
|
res, err := db.ExecContext(
|
||||||
|
ctx,
|
||||||
|
"UPDATE users SET name = $1 WHERE id = $2",
|
||||||
|
"William Mandella", 1,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ func Open() {
|
||||||
dbFoo, _ := sql.Open("pgx", "host=foo")
|
dbFoo, _ := sql.Open("pgx", "host=foo")
|
||||||
dbBar, _ := sql.Open("pgx", "host=bar")
|
dbBar, _ := sql.Open("pgx", "host=bar")
|
||||||
cluster, err := hasql.NewCluster(
|
cluster, err := hasql.NewCluster(
|
||||||
[]hasql.Node{hasql.NewNode("foo", dbFoo), hasql.NewNode("bar", dbBar) },
|
[]hasql.Node{hasql.NewNode("foo", dbFoo), hasql.NewNode("bar", dbBar)},
|
||||||
checkers.PostgreSQL,
|
checkers.PostgreSQL,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,7 +13,8 @@ func TxExhaust(ctx context.Context, db *sql.DB) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = tx.ExecContext(ctx, `UPDATE users SET name = "Surl/Tesh-echer" WHERE id = 1`); err != nil {
|
_, err = tx.ExecContext(ctx, `UPDATE users SET name = "Surl/Tesh-echer" WHERE id = 1`)
|
||||||
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,16 +100,14 @@ database/sql
|
||||||
|
|
||||||
.code prepare/prepare.go /^func Prepare/,/^}/
|
.code prepare/prepare.go /^func Prepare/,/^}/
|
||||||
|
|
||||||
* *sql.DB - это пул коннектов
|
* Настройка *sql.DB
|
||||||
|
|
||||||
* Настройка DB
|
|
||||||
|
|
||||||
- func (db *DB) SetConnMaxIdleTime(d time.Duration)
|
- func (db *DB) SetConnMaxIdleTime(d time.Duration)
|
||||||
- func (db *DB) SetConnMaxLifetime(d time.Duration)
|
- func (db *DB) SetConnMaxLifetime(d time.Duration)
|
||||||
- func (db *DB) SetMaxIdleConns(n int)
|
- func (db *DB) SetMaxIdleConns(n int)
|
||||||
- func (db *DB) SetMaxOpenConns(n int)
|
- func (db *DB) SetMaxOpenConns(n int)
|
||||||
|
|
||||||
* Статистика DB
|
* Статистика *sql.DB
|
||||||
|
|
||||||
- func (db *DB) Stats() DBStats
|
- func (db *DB) Stats() DBStats
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
package sqlx
|
package sqlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QueryerContext interface {
|
type QueryerContext interface {
|
||||||
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
||||||
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
|
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
|
||||||
QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
|
QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExecerContext interface {
|
type ExecerContext interface {
|
||||||
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExtContext interface {
|
type ExtContext interface {
|
||||||
QueryerContext
|
QueryerContext
|
||||||
ExecerContext
|
ExecerContext
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ func Begin(ctx context.Context, db *sql.DB) {
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
if _, err = tx.ExecContext(ctx, `UPDATE users SET name = "Tyador Borlú" WHERE id = 1`); err != nil {
|
_, err = tx.ExecContext(ctx, `UPDATE users SET name = "Tyador Borlú" WHERE id = 1`)
|
||||||
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue