Skip to content

Instantly share code, notes, and snippets.

@rueian
rueian / main.go
Created June 8, 2020 09:41
envoy
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
package main
import (
"container/ring"
"fmt"
"math/rand"
"strconv"
"sync/atomic"
"unsafe"
)
@rueian
rueian / flasklab.py
Created May 5, 2020 18:44
flask with mysql connection pool
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

@rueian
rueian / node-postgres-prep.ts
Last active March 17, 2020 18:22
node-postgres prep test
'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 {
@rueian
rueian / goprep.md
Last active March 16, 2020 12:03
golang pg lib prep matrix
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

@rueian
rueian / pgx.go
Last active March 16, 2020 11:56
pgx prep test
package main
import (
"context"
"crypto/rand"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
"time"
)
@rueian
rueian / gorm.go
Last active March 16, 2020 12:05
gorm prep test
package main
import (
"crypto/rand"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"time"
)
const (
@rueian
rueian / gopg.go
Last active March 16, 2020 11:51
gopg prep test
package main
import (
"crypto/rand"
"github.com/go-pg/pg/v9"
"time"
)
const (
pgURL = "postgres://postgres@localhost:5433/postgres?sslmode=disable"