| lib | named prepared statement | binary bytea | binary timestamptz | binary uuid |
|---|---|---|---|---|
| node-postgres^7.18.2 | o | half | x | x |
node-postgres^7.18.2 的 bytea 參數用 binary,回傳用 text
| package main | |
| import ( | |
| "fmt" | |
| "io/ioutil" | |
| "os" | |
| "gopkg.in/yaml.v2" | |
| ) |
| package main | |
| import ( | |
| "container/ring" | |
| "fmt" | |
| "math/rand" | |
| "strconv" | |
| "sync/atomic" | |
| "unsafe" | |
| ) |
| from flask import Flask, g | |
| import os | |
| import mysql.connector.pooling | |
| app = Flask(__name__) | |
| cnxpool = mysql.connector.pooling.MySQLConnectionPool( | |
| host=os.getenv('MYSQL_HOST', '127.0.0.1'), | |
| user=os.getenv('MYSQL_USER', 'flasklab'), | |
| password=os.getenv('MYSQL_DATABASE', 'flasklab'), |
| lib | named prepared statement | binary bytea | binary timestamptz | binary uuid |
|---|---|---|---|---|
| node-postgres^7.18.2 | o | half | x | x |
node-postgres^7.18.2 的 bytea 參數用 binary,回傳用 text
| 'use strict'; | |
| const crypto = require('crypto'); | |
| const { Client } = require('pg'); | |
| const url = 'postgres://postgres@localhost:5433/postgres?sslmode=disable'; | |
| const text = '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 *'; | |
| const values = ['foo', crypto.randomBytes(10), new Date()]; | |
| (async function() { |
| package main | |
| import ( | |
| "crypto/rand" | |
| "database/sql" | |
| _ "github.com/lib/pq" | |
| "testing" | |
| ) | |
| type test struct { |
| lib | named prepared statement | binary bytea | binary timestamptz | binary uuid |
|---|---|---|---|---|
| lib/pq | o | o | x | x |
| gopg | o | x | x | x |
| gorm | x | half | x | x |
| pgx | o | o | o | o |
Gorm 的 bytea 在未開啟 binary_parameters=yes 前是參數用 text 回傳用 binary,開啟之後是參數用 binary 回傳用 text
| package main | |
| import ( | |
| "context" | |
| "crypto/rand" | |
| "github.com/jackc/pgtype" | |
| "github.com/jackc/pgx/v4" | |
| "time" | |
| ) |
| package main | |
| import ( | |
| "crypto/rand" | |
| "github.com/jinzhu/gorm" | |
| _ "github.com/jinzhu/gorm/dialects/postgres" | |
| "time" | |
| ) | |
| const ( |
| package main | |
| import ( | |
| "crypto/rand" | |
| "github.com/go-pg/pg/v9" | |
| "time" | |
| ) | |
| const ( | |
| pgURL = "postgres://postgres@localhost:5433/postgres?sslmode=disable" |