aboutsummaryrefslogtreecommitdiff
path: root/src/server/IDatabase.ts
blob: 2274792b3d95288a2ce08bcb63336d2901db7d11 (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 { Transferable } from './Message';

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: any, collectionName?: string): Promise<void>;

    getDocument(id: string, fn: (result?: Transferable) => void, collectionName?: string): void;
    getDocuments(ids: string[], fn: (result: Transferable[]) => 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>;
}