mirror of https://github.com/VinGarcia/ksql.git
Update README and examples to use `defer db.Close()`
parent
d98c30e91a
commit
6bce16be80
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue