Last active
March 16, 2020 12:05
-
-
Save rueian/73146463c85d3c6dc70d27e52aa600f3 to your computer and use it in GitHub Desktop.
gorm 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/jinzhu/gorm" | |
| _ "github.com/jinzhu/gorm/dialects/postgres" | |
| "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() { | |
| g, _ := gorm.Open("postgres", pgURL) | |
| defer g.Close() | |
| v := make([]byte, 10) | |
| rand.Read(v) | |
| g.Exec(query, "foo", v, time.Now()) | |
| } | |
| // Proxy Output | |
| // | |
| // Simple Query: len=1 query=; | |
| // Parse Query: name= 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=37 value=\240\264\301k\327\313\036\030\032\270 | |
| // Bind Parameter: 2 format=text len=32 value=2020-03-16 19:53:16.964056+08:00 | |
| // Bind ResultFormatCodes: column=0 format=text | |
| // Bind ResultFormatCodes: column=1 format=byte | |
| // Bind ResultFormatCodes: column=2 format=text | |
| // Result DataRaw: column=0 format=text len=3 value=foo | |
| // Result DataRaw: column=1 format=byte len=10 hex=a0b4c16bd7cb1e181ab8 | |
| // Result DataRaw: column=2 format=text len=29 value=2020-03-16 11:53:16.964056+00 | |
| // Proxy Output With &binary_parameters=yes | |
| // | |
| // Simple Query: len=1 query=; | |
| // Parse Query: name= 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=byte len=10 hex=4da8568c6b67e2b476aa | |
| // Bind Parameter: 2 format=text len=32 value=2020-03-16 19:52:09.738223+08: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=\x4da8568c6b67e2b476aa | |
| // Result DataRaw: column=2 format=text len=29 value=2020-03-16 11:52:09.738223+00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment