diff --git a/README.md b/README.md index db25c43..8e9359e 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ type User struct { func main() { ctx := context.Background() db, err := kpgx.New(ctx, os.Getenv("POSTGRES_URL"), ksql.Config{}) + if err != nil { + log.Fatalf("unable connect to database: %s", err) + } + defer db.Close() // For querying only some attributes you can // create a custom struct like this: @@ -247,6 +251,7 @@ func main() { if err != nil { panic(err.Error()) } + defer db.Close() // In the definition below, please note that BLOB is // the only type we can use in sqlite for storing JSON. diff --git a/examples/all_adapters/all_adapters.go b/examples/all_adapters/all_adapters.go index 36aa9a1..57e79f8 100644 --- a/examples/all_adapters/all_adapters.go +++ b/examples/all_adapters/all_adapters.go @@ -48,6 +48,8 @@ func main() { if err != nil { log.Fatalf("unable to open database, reason: %s", err) } + defer db.Close() + _, err = db.Exec(ctx, `CREATE TABLE users ( id serial PRIMARY KEY, age INT, @@ -64,6 +66,8 @@ func main() { if err != nil { log.Fatalf("unable to open database: %s", err) } + defer db.Close() + _, err = db.Exec(ctx, `CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, age INT, @@ -80,6 +84,7 @@ func main() { if err != nil { log.Fatalf("unable to open database: %s", err) } + defer db.Close() // In the example below NVARCHAR is the format // we are using for storing JSON: @@ -99,6 +104,7 @@ func main() { if err != nil { log.Fatalf("unable to open database: %s", err) } + defer db.Close() // In the definition below, please note that BLOB is // the only type we can use in sqlite for storing JSON. diff --git a/examples/crud/crud.go b/examples/crud/crud.go index cf018fa..91624e7 100644 --- a/examples/crud/crud.go +++ b/examples/crud/crud.go @@ -56,6 +56,7 @@ func main() { if err != nil { panic(err.Error()) } + defer db.Close() // In the definition below, please note that BLOB is // the only type we can use in sqlite for storing JSON.