2022-03-15 14:35:15 +00:00
|
|
|
import * as Types from 'app/plugin/DocApiTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Offer CRUD-style operations on a table.
|
|
|
|
*/
|
|
|
|
export interface TableOperations {
|
2022-03-23 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* Create a record or records.
|
|
|
|
*/
|
2022-03-15 14:35:15 +00:00
|
|
|
create(records: Types.NewRecord, options?: OpOptions): Promise<Types.MinimalRecord>;
|
|
|
|
create(records: Types.NewRecord[], options?: OpOptions): Promise<Types.MinimalRecord[]>;
|
|
|
|
|
2022-03-23 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* Update a record or records.
|
|
|
|
*/
|
2022-03-15 14:35:15 +00:00
|
|
|
update(records: Types.Record|Types.Record[], options?: OpOptions): Promise<void>;
|
|
|
|
|
2022-03-23 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* Delete a record or records.
|
|
|
|
*/
|
2022-05-05 11:42:50 +00:00
|
|
|
destroy(recordIds: Types.RecordId|Types.RecordId[]): Promise<void>;
|
2022-03-15 14:35:15 +00:00
|
|
|
|
2022-03-23 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* Add or update a record or records.
|
|
|
|
*/
|
2022-03-15 14:35:15 +00:00
|
|
|
upsert(records: Types.AddOrUpdateRecord|Types.AddOrUpdateRecord[],
|
|
|
|
options?: UpsertOptions): Promise<void>;
|
|
|
|
|
2022-03-23 13:41:34 +00:00
|
|
|
/**
|
|
|
|
* Determine the tableId of the table.
|
|
|
|
*/
|
2022-03-16 18:33:48 +00:00
|
|
|
getTableId(): Promise<string>;
|
|
|
|
|
2022-03-15 14:35:15 +00:00
|
|
|
// TODO: offer a way to query the table.
|
|
|
|
// select(): Records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General options for table operations.
|
|
|
|
*/
|
|
|
|
export interface OpOptions {
|
2022-05-24 20:22:41 +00:00
|
|
|
/** Whether to parse strings based on the column type. Defaults to true. */
|
|
|
|
parseStrings?: boolean;
|
2022-03-15 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-24 20:22:41 +00:00
|
|
|
* Extra options for upserts.
|
2022-03-15 14:35:15 +00:00
|
|
|
*/
|
|
|
|
export interface UpsertOptions extends OpOptions {
|
2022-05-24 20:22:41 +00:00
|
|
|
/** Permit inserting a record. Defaults to true. */
|
|
|
|
add?: boolean;
|
|
|
|
/** Permit updating a record. Defaults to true. */
|
|
|
|
update?: boolean;
|
|
|
|
/** Whether to update none, one, or all matching records. Defaults to "first". */
|
|
|
|
onMany?: 'none' | 'first' | 'all';
|
|
|
|
/** Allow "wildcard" operation. Defaults to false. */
|
|
|
|
allowEmptyRequire?: boolean;
|
2022-03-15 14:35:15 +00:00
|
|
|
}
|