@planetscale/database
Advanced tools
Comparing version 1.12.0 to 1.13.0
export { format } from './sanitization.js'; | ||
export { hex } from './text.js'; | ||
type Row = Record<string, any> | any[]; | ||
type Row<T extends ExecuteAs = 'object'> = T extends 'array' ? any[] : T extends 'object' ? Record<string, any> : never; | ||
interface VitessError { | ||
@@ -14,6 +14,6 @@ message: string; | ||
type Types = Record<string, string>; | ||
export interface ExecutedQuery { | ||
export interface ExecutedQuery<T = Row<'array'> | Row<'object'>> { | ||
headers: string[]; | ||
types: Types; | ||
rows: Row[]; | ||
rows: T[]; | ||
fields: Field[]; | ||
@@ -62,6 +62,2 @@ size: number; | ||
type ExecuteAs = 'array' | 'object'; | ||
type ExecuteOptions = { | ||
as?: ExecuteAs; | ||
cast?: Cast; | ||
}; | ||
type ExecuteArgs = object | any[] | null; | ||
@@ -72,3 +68,10 @@ export declare class Client { | ||
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
connection(): Connection; | ||
@@ -80,3 +83,10 @@ } | ||
constructor(conn: Connection); | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
} | ||
@@ -90,3 +100,10 @@ export declare class Connection { | ||
refresh(): Promise<void>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
private createSession; | ||
@@ -93,0 +110,0 @@ } |
@@ -20,5 +20,2 @@ "use strict"; | ||
exports.DatabaseError = DatabaseError; | ||
const defaultExecuteOptions = { | ||
as: 'object' | ||
}; | ||
class Client { | ||
@@ -31,3 +28,3 @@ constructor(config) { | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
return this.connection().execute(query, args, options); | ||
@@ -44,3 +41,3 @@ } | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
return this.conn.execute(query, args, options); | ||
@@ -92,3 +89,3 @@ } | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
const url = new URL('/psdb.v1alpha1.Database/Execute', this.url); | ||
@@ -95,0 +92,0 @@ const formatter = this.config.format || sanitization_js_1.format; |
@@ -39,3 +39,3 @@ "use strict"; | ||
if (value instanceof Date) { | ||
return quote(value.toISOString().replace('Z', '')); | ||
return quote(value.toISOString().slice(0, -1)); | ||
} | ||
@@ -42,0 +42,0 @@ return quote(value.toString()); |
@@ -1,1 +0,1 @@ | ||
export declare const Version = "1.12.0"; | ||
export declare const Version = "1.13.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Version = void 0; | ||
exports.Version = '1.12.0'; | ||
exports.Version = '1.13.0'; |
export { format } from './sanitization.js'; | ||
export { hex } from './text.js'; | ||
type Row = Record<string, any> | any[]; | ||
type Row<T extends ExecuteAs = 'object'> = T extends 'array' ? any[] : T extends 'object' ? Record<string, any> : never; | ||
interface VitessError { | ||
@@ -14,6 +14,6 @@ message: string; | ||
type Types = Record<string, string>; | ||
export interface ExecutedQuery { | ||
export interface ExecutedQuery<T = Row<'array'> | Row<'object'>> { | ||
headers: string[]; | ||
types: Types; | ||
rows: Row[]; | ||
rows: T[]; | ||
fields: Field[]; | ||
@@ -62,6 +62,2 @@ size: number; | ||
type ExecuteAs = 'array' | 'object'; | ||
type ExecuteOptions = { | ||
as?: ExecuteAs; | ||
cast?: Cast; | ||
}; | ||
type ExecuteArgs = object | any[] | null; | ||
@@ -72,3 +68,10 @@ export declare class Client { | ||
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
connection(): Connection; | ||
@@ -80,3 +83,10 @@ } | ||
constructor(conn: Connection); | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
} | ||
@@ -90,3 +100,10 @@ export declare class Connection { | ||
refresh(): Promise<void>; | ||
execute(query: string, args?: ExecuteArgs, options?: ExecuteOptions): Promise<ExecutedQuery>; | ||
execute<T = Row<'object'>>(query: string, args?: ExecuteArgs, options?: { | ||
as?: 'object'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
execute<T = Row<'array'>>(query: string, args: ExecuteArgs, options: { | ||
as: 'array'; | ||
cast?: Cast; | ||
}): Promise<ExecutedQuery<T>>; | ||
private createSession; | ||
@@ -93,0 +110,0 @@ } |
@@ -14,5 +14,2 @@ import { format } from './sanitization.js'; | ||
} | ||
const defaultExecuteOptions = { | ||
as: 'object' | ||
}; | ||
export class Client { | ||
@@ -25,3 +22,3 @@ constructor(config) { | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
return this.connection().execute(query, args, options); | ||
@@ -37,3 +34,3 @@ } | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
return this.conn.execute(query, args, options); | ||
@@ -85,3 +82,3 @@ } | ||
} | ||
async execute(query, args = null, options = defaultExecuteOptions) { | ||
async execute(query, args = null, options = { as: 'object' }) { | ||
const url = new URL('/psdb.v1alpha1.Database/Execute', this.url); | ||
@@ -88,0 +85,0 @@ const formatter = this.config.format || format; |
@@ -35,3 +35,3 @@ export function format(query, values) { | ||
if (value instanceof Date) { | ||
return quote(value.toISOString().replace('Z', '')); | ||
return quote(value.toISOString().slice(0, -1)); | ||
} | ||
@@ -38,0 +38,0 @@ return quote(value.toString()); |
@@ -1,1 +0,1 @@ | ||
export declare const Version = "1.12.0"; | ||
export declare const Version = "1.13.0"; |
@@ -1,1 +0,1 @@ | ||
export const Version = '1.12.0'; | ||
export const Version = '1.13.0'; |
{ | ||
"name": "@planetscale/database", | ||
"version": "1.12.0", | ||
"version": "1.13.0", | ||
"description": "A Fetch API-compatible PlanetScale database driver", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -1,3 +0,5 @@ | ||
# PlanetScale Serverless Driver for JavaScript | ||
![PlanetScale serverless driver for JavaScript](https://github.com/planetscale/database-js/assets/440926/0dfab33f-b01f-4814-ae40-c5fe5cbe94e3) | ||
# PlanetScale serverless driver for JavaScript | ||
A Fetch API-compatible PlanetScale database driver for serverless and edge compute platforms that require HTTP external connections, such as Cloudflare Workers or Vercel Edge Functions | ||
@@ -7,3 +9,3 @@ | ||
``` | ||
```sh | ||
npm install @planetscale/database | ||
@@ -228,3 +230,3 @@ ``` | ||
``` | ||
```sh | ||
npm install | ||
@@ -234,4 +236,8 @@ npm test | ||
## Need help? | ||
Get help from [the PlanetScale support team](https://support.planetscale.com/), or [join our community on Discord](https://discord.gg/EqrcEf2dGv) or [GitHub discussion board](https://github.com/planetscale/discussion/discussions) to see how others are using PlanetScale. | ||
## License | ||
Distributed under the Apache 2.0 license. See LICENSE for details. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
47164
860
241
6