Last active
March 16, 2020 11:51
-
-
Save rueian/d1476bc1cacd68456017f88a1690fada to your computer and use it in GitHub Desktop.
gopg prep test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "crypto/rand" | |
| "github.com/go-pg/pg/v9" | |
| "time" | |
| ) | |
| const ( | |
| pgURL = "postgres://postgres@localhost:5433/postgres?sslmode=disable" | |
| query = "INSERT INTO kv (key, value, updated_at) VALUES ($1::text, $2::bytea, $3::timestamptz) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at RETURNING *;" | |
| ) | |
| func main() { | |
| opt, _ := pg.ParseURL(pgURL) | |
| db := pg.Connect(opt) | |
| defer db.Close() | |
| stmt, _ := db.Prepare(query) | |
| defer stmt.Close() | |
| v := make([]byte, 10) | |
| rand.Read(v) | |
| stmt.Exec("foo", v, time.Now()) | |
| } | |
| // Proxy Output | |
| // | |
| // Parse Query: name=1 query=INSERT INTO kv (key, value, updated_at) VALUES ($1::text, $2::bytea, $3::timestamptz) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = EXCLUDED.updated_at RETURNING *; | |
| // Bind Parameter: 0 format=text len=3 value=foo | |
| // Bind Parameter: 1 format=text len=22 value=\xc3462c946d3f8be48fd8 | |
| // Bind Parameter: 2 format=text len=35 value=2020-03-16 11:50:03.419283+00:00:00 | |
| // Bind ResultFormatCodes: no result format codes | |
| // Result DataRaw: column=0 format=text len=3 value=foo | |
| // Result DataRaw: column=1 format=text len=22 value=\xc3462c946d3f8be48fd8 | |
| // Result DataRaw: column=2 format=text len=29 value=2020-03-16 11:50:03.419283+00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment