@tidbcloud/serverless
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -39,2 +39,5 @@ interface ServerlessError { | ||
} | ||
interface TxOptions { | ||
isolation?: 'READ COMMITTED' | 'REPEATABLE READ'; | ||
} | ||
type ExecuteArgs = object | any[] | null; | ||
@@ -60,3 +63,3 @@ | ||
constructor(conn: Connection); | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<FullResult | Row[]>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions, txOptions?: TxOptions): Promise<FullResult | Row[]>; | ||
commit(): Promise<FullResult | Row[]>; | ||
@@ -69,4 +72,4 @@ rollback(): Promise<FullResult | Row[]>; | ||
constructor(config: Config); | ||
begin(): Promise<Tx>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<FullResult | Row[]>; | ||
begin(txOptions?: TxOptions): Promise<Tx>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions, txOptions?: TxOptions): Promise<FullResult | Row[]>; | ||
} | ||
@@ -73,0 +76,0 @@ declare function connect(config: Config): Connection; |
@@ -140,6 +140,6 @@ // src/format.ts | ||
// src/version.ts | ||
var Version = "0.0.6"; | ||
var Version = "0.0.7"; | ||
// src/serverless.ts | ||
async function postQuery(config, body, session = "") { | ||
async function postQuery(config, body, session = "", isolationLevel = null) { | ||
let fetchCacheOption = { cache: "no-store" }; | ||
@@ -155,12 +155,16 @@ try { | ||
const database = config.database ?? ""; | ||
const headers = { | ||
"Content-Type": "application/json", | ||
"User-Agent": `serverless-js/${Version}`, | ||
Authorization: `Basic ${auth}`, | ||
"TiDB-Database": database, | ||
"TiDB-Session": session | ||
}; | ||
if (isolationLevel) { | ||
headers["TiDB-Isolation-Level"] = isolationLevel; | ||
} | ||
const response = await fetch2(url.toString(), { | ||
method: "POST", | ||
body, | ||
headers: { | ||
"Content-Type": "application/json", | ||
"User-Agent": `serverless-js/${Version}`, | ||
Authorization: `Basic ${auth}`, | ||
"TiDB-Database": database, | ||
"TiDB-Session": session | ||
}, | ||
headers, | ||
...fetchCacheOption | ||
@@ -194,4 +198,4 @@ }); | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
return this.conn.execute(query, args, options); | ||
async execute(query, args = null, options = defaultExecuteOptions, txOptions = {}) { | ||
return this.conn.execute(query, args, options, txOptions); | ||
} | ||
@@ -229,12 +233,12 @@ async commit() { | ||
} | ||
async begin() { | ||
async begin(txOptions = {}) { | ||
const conn = new _Connection(this.config); | ||
const tx = new Tx(conn); | ||
await tx.execute("BEGIN"); | ||
await tx.execute("BEGIN", void 0, void 0, txOptions); | ||
return tx; | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = defaultExecuteOptions, txOptions = {}) { | ||
const sql = args ? format(query, args) : query; | ||
const body = JSON.stringify({ query: sql }); | ||
const resp = await postQuery(this.config, body, this.session ?? ""); | ||
const resp = await postQuery(this.config, body, this.session ?? "", sql == "BEGIN" ? txOptions.isolation : null); | ||
this.session = resp?.session ?? null; | ||
@@ -241,0 +245,0 @@ if (this.session === null || this.session === "") { |
{ | ||
"name": "@tidbcloud/serverless", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "TiDB Serverless driver", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35759
663
4