KingbaseES client for MoonBit: PostgreSQL wire protocol 3.0, SCRAM-SHA-256, text COPY, and a dialect layer for the pg / oracle / mysql / sqlserver compatibility modes
{
"deps": {
"shiyukonghui/kingbase-client": { "path": "../kingbase-client" }
}
}moon add shiyukonghui/kingbase-clientimport {
"shiyukonghui/kingbase-client" @kb,
"shiyukonghui/kingbase-client/dialect" @dialect,
}let cfg = @kb.new_config("db.example.com", 54321, "app", secret, "app")
let client = @kb.connect(cfg)
let rs = client.query("select id, amount from mb_orders where id = 42")
println(rs.cell(0, 1))
client.close()let stream = client.copy_in("copy mb_orders (id, name, amount) from stdin")
let row = @kb.new_copy_row(@buffer.Buffer(size_hint=1024))
row.write_int64(7L)
row.write_text("product-1")
row.write_decimal(1234567L, 4) // numeric(18,4) -> 123.4567
row.end_row()
stream.send_data(row.take())
println(stream.finish()) // "COPY 1"let d = client.dialect()
let n = client.query("update mb_orders set status = 'closed' where id <= 1000").affected()
println(n) // 1000 -- "UPDATE 1000"; `SELECT 1` and `COPY 5000` parse the same way
client.execute(d.begin_statement()) // "begin", or "begin transaction" in sqlserver mode
client.execute("commit")let d = client.dialect()
println(d.mode) // Sqlserver
println(d.setting("sql_mode")) // ONLY_FULL_GROUP_BY,ANSI_QUOTES
println(d.column_type(@dialect.Timestamp)) // datetime
println(d.limit_clause(100, 500)) // offset 500 rows fetch next 100 rows only| Rule | pg | oracle | mysql | sqlserver |
|---|---|---|---|---|
| integer type | integer | number(10) | int | int |
| big integer | bigint | number(19) | bigint | bigint |
| date-and-time type | timestamp | timestamp | datetime | datetime |
| boolean column type | boolean | number(1) | boolean | bit |
| boolean text, read back after a COPY round trip | t / f | 1 / 0 | t / f | 1 / 0 |
| '' stored in a varchar | not NULL | NULL | not NULL | not NULL |
| pagination the dialect emits | limit n offset m | offset m rows fetch next n rows only | limit n offset m | offset m rows fetch next n rows only |
| also accepted there | offset/fetch | top, limit m,n, rownum | top, limit m,n, rownum | top, limit m,n |
| identifier quoting | "x" | "x" | "x" and `x` | "x" and [x] |
| string concatenation | \|\| | \|\| | concat() | + (\|\| refused under ANSI_QUOTES) |
| catalog views | pg_* only | sys_* and pg_* | sys_* and pg_* | sys_* and pg_* |
| opens a transaction | begin | begin | begin | begin transaction only |
| return type of sum(integer) | bigint | numeric | bigint | int |
| smalldatetime | absent | absent | absent | present |
| varchar2 / number | absent | present | present | absent |
kingbase_bench probe --host=IP --port=PORT --user=NAME --password=SECRET --database=NAME # 52 read-only checks
kingbase_bench livecheck --host=IP ... # 14 dialect rules, one verdict each
kingbase_bench crud --host=IP ... # 37 single-row and batch DML checkscmd //c "native.cmd check --target native" # 0 errors, 0 warnings
cmd //c "native.cmd test --target native" # the offline suite
cmd //c "native.cmd info --target native" # regenerate pkg.generated.mbti
moon package --list # what would be uploadedmoon register # once, at https://mooncakes.io
moon login # writes ~/.moon/credentials.json
moon publish # version must be SemVer and higher than any published onepub struct Config {
host : String
port : Int
user : String
password : String
database : String
detect_dialect : Bool
fallback_mode : Mode?
}pub(all) struct ServerError {
severity : String
code : String
message : String
}fn new_config(host : String, port : Int, user : String, password : String, database : String) -> Configfn now_us() -> Int64fn sleep_ms(ms : Int) -> UnitInstall
Download zipKingbaseES client for MoonBit: PostgreSQL wire protocol 3.0, SCRAM-SHA-256, text COPY, and a dialect layer for the pg / oracle / mysql / sqlserver compatibility modes