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.
|
|
|
|
* By default, string field values will be parsed based on the column type.
|
|
|
|
* This can be disabled.
|
|
|
|
*/
|
|
|
|
export interface OpOptions {
|
2022-03-23 13:41:34 +00:00
|
|
|
parseStrings?: boolean; /** whether to parse strings based on the column type. */
|
2022-03-15 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra options for upserts. By default, add and update are true,
|
|
|
|
* onMany is first, and allowEmptyRequire is false.
|
|
|
|
*/
|
|
|
|
export interface UpsertOptions extends OpOptions {
|
2022-03-23 13:41:34 +00:00
|
|
|
add?: boolean; /** permit inserting a record */
|
|
|
|
update?: boolean; /** permit updating a record */
|
|
|
|
onMany?: 'none' | 'first' | 'all'; /** whether to update none, one, or all matching records */
|
|
|
|
allowEmptyRequire?: boolean; /** allow "wildcard" operation */
|
2022-03-15 14:35:15 +00:00
|
|
|
}
|