mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
add an endpoint for doing SQL selects (#641)
* add an endpoint for doing SQL selects This adds an endpoint for doing SQL selects directly on a Grist document. Other kinds of statements are not supported. There is a default timeout of a second on queries. This follows loosely an API design by Alex Hall. Co-authored-by: jarek <jaroslaw.sadzinski@gmail.com>
This commit is contained in:
@@ -12,20 +12,50 @@ import { OpenMode, quoteIdent } from 'app/server/lib/SQLiteDB';
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface Statement {}
|
||||
|
||||
// Some facts about the wrapper implementation.
|
||||
export interface MinDBOptions {
|
||||
// is interruption implemented?
|
||||
canInterrupt: boolean;
|
||||
|
||||
// Do all methods apart from exec() process at most one
|
||||
// statement?
|
||||
bindableMethodsProcessOneStatement: boolean;
|
||||
}
|
||||
|
||||
export interface MinDB {
|
||||
// This method is expected to be able to handle multiple
|
||||
// semicolon-separated statements, as for sqlite3_exec:
|
||||
// https://www.sqlite.org/c3ref/exec.html
|
||||
exec(sql: string): Promise<void>;
|
||||
|
||||
// For all these methods, sql should ultimately be passed
|
||||
// to sqlite3_prepare_v2 or later, and any tail text ignored after
|
||||
// the first complete statement, so only the first statement is
|
||||
// used if there are multiple.
|
||||
// https://www.sqlite.org/c3ref/prepare.html
|
||||
run(sql: string, ...params: any[]): Promise<MinRunResult>;
|
||||
get(sql: string, ...params: any[]): Promise<ResultRow|undefined>;
|
||||
all(sql: string, ...params: any[]): Promise<ResultRow[]>;
|
||||
prepare(sql: string, ...params: any[]): Promise<PreparedStatement>;
|
||||
runAndGetId(sql: string, ...params: any[]): Promise<number>;
|
||||
close(): Promise<void>;
|
||||
allMarshal(sql: string, ...params: any[]): Promise<Buffer>;
|
||||
|
||||
close(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Limit the number of ATTACHed databases permitted.
|
||||
*/
|
||||
limitAttach(maxAttach: number): Promise<void>;
|
||||
|
||||
/**
|
||||
* Stop all current queries.
|
||||
*/
|
||||
interrupt?(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get some facts about the wrapper.
|
||||
*/
|
||||
getOptions?(): MinDBOptions;
|
||||
}
|
||||
|
||||
export interface MinRunResult {
|
||||
|
||||
Reference in New Issue
Block a user