aboutsummaryrefslogtreecommitdiff
path: root/src/server/IDatabase.ts
blob: 481b64d4aec11b4855840e43b88a973f6dbdef3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as mongodb from 'mongodb';
import { serializedDoctype } from '../fields/ObjectField';

export const DocumentsCollection = 'documents';
export interface IDatabase {
    update(id: string, value: any, callback: (err: mongodb.MongoError, res: mongodb.UpdateResult) => void, upsert?: boolean, collectionName?: string): Promise<void>;
    updateMany(query: any, update: any, collectionName?: string): Promise<mongodb.UpdateResult>;

    replace(id: string, value: any, callback: (err: mongodb.MongoError, res: mongodb.UpdateResult) => void, upsert?: boolean, collectionName?: string): void;

    delete(query: any, collectionName?: string): Promise<mongodb.DeleteResult>;
    delete(id: string, collectionName?: string): Promise<mongodb.DeleteResult>;

    dropSchema(...schemaNames: string[]): Promise<any>;

    insert(value: { _id: string }, collectionName?: string): Promise<void>;

    getDocument(id: string, fn: (result?: serializedDoctype) => void, collectionName?: string): void;
    getDocuments(ids: string[], fn: (result: serializedDoctype[]) => void, collectionName?: string): void;
    getCollectionNames(): Promise<string[]>;
    visit(ids: string[], fn: (result: any) => string[] | Promise<string[]>, collectionName?: string): Promise<void>;

    query(query: { [key: string]: any }, projection?: { [key: string]: 0 | 1 }, collectionName?: string): Promise<mongodb.FindCursor>;
}