From e1cf5d8de379a11fb6c80ced90cff8e57894d85e Mon Sep 17 00:00:00 2001 From: Ilya Sinelnikov Date: Thu, 8 Apr 2021 14:37:21 +0300 Subject: [PATCH] Make all text fit sql slides --- lectures/07-sql/conf/stats.go | 22 +++++++++++----------- lectures/07-sql/exec/exec.go | 6 +++++- lectures/07-sql/hasql/open.go | 2 +- lectures/07-sql/resources/tx.go | 3 ++- lectures/07-sql/sql.slide | 6 ++---- lectures/07-sql/sqlx/ext.go | 18 +++++++++--------- lectures/07-sql/tx/tx.go | 3 ++- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lectures/07-sql/conf/stats.go b/lectures/07-sql/conf/stats.go index a744a85..c6d8c6c 100644 --- a/lectures/07-sql/conf/stats.go +++ b/lectures/07-sql/conf/stats.go @@ -1,17 +1,17 @@ package conf 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 - 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 - Idle int // The number of idle connections; added in Go 1.11 + // Pool Status + 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 + Idle int // The number of idle connections; added in Go 1.11 - // Counters - 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 - 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 - MaxLifetimeClosed int64 // The total number of connections closed due to SetConnMaxLifetime; added in Go 1.11 + // Counters + 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 + 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 + MaxLifetimeClosed int64 // The total number of connections closed due to SetConnMaxLifetime; added in Go 1.11 } diff --git a/lectures/07-sql/exec/exec.go b/lectures/07-sql/exec/exec.go index 2c56532..cdd25f7 100644 --- a/lectures/07-sql/exec/exec.go +++ b/lectures/07-sql/exec/exec.go @@ -7,7 +7,11 @@ import ( ) 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 { log.Fatal(err) } diff --git a/lectures/07-sql/hasql/open.go b/lectures/07-sql/hasql/open.go index 5759331..303e14c 100644 --- a/lectures/07-sql/hasql/open.go +++ b/lectures/07-sql/hasql/open.go @@ -12,7 +12,7 @@ func Open() { dbFoo, _ := sql.Open("pgx", "host=foo") dbBar, _ := sql.Open("pgx", "host=bar") 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, ) if err != nil { diff --git a/lectures/07-sql/resources/tx.go b/lectures/07-sql/resources/tx.go index 0607ba8..6e6beac 100644 --- a/lectures/07-sql/resources/tx.go +++ b/lectures/07-sql/resources/tx.go @@ -13,7 +13,8 @@ func TxExhaust(ctx context.Context, db *sql.DB) { 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) return } diff --git a/lectures/07-sql/sql.slide b/lectures/07-sql/sql.slide index 8391a44..5591789 100644 --- a/lectures/07-sql/sql.slide +++ b/lectures/07-sql/sql.slide @@ -100,16 +100,14 @@ database/sql .code prepare/prepare.go /^func Prepare/,/^}/ -* *sql.DB - это пул коннектов - -* Настройка DB +* Настройка *sql.DB - func (db *DB) SetConnMaxIdleTime(d time.Duration) - func (db *DB) SetConnMaxLifetime(d time.Duration) - func (db *DB) SetMaxIdleConns(n int) - func (db *DB) SetMaxOpenConns(n int) -* Статистика DB +* Статистика *sql.DB - func (db *DB) Stats() DBStats diff --git a/lectures/07-sql/sqlx/ext.go b/lectures/07-sql/sqlx/ext.go index 8cf6953..696458a 100644 --- a/lectures/07-sql/sqlx/ext.go +++ b/lectures/07-sql/sqlx/ext.go @@ -1,23 +1,23 @@ package sqlx import ( - "context" - "database/sql" + "context" + "database/sql" - "github.com/jmoiron/sqlx" + "github.com/jmoiron/sqlx" ) type QueryerContext interface { - QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) - QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) - QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row + QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) + QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) + QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row } 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 { - QueryerContext - ExecerContext + QueryerContext + ExecerContext } diff --git a/lectures/07-sql/tx/tx.go b/lectures/07-sql/tx/tx.go index f7da2e5..abca9f6 100644 --- a/lectures/07-sql/tx/tx.go +++ b/lectures/07-sql/tx/tx.go @@ -13,7 +13,8 @@ func Begin(ctx context.Context, db *sql.DB) { } 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) }