/** @module BigDB */ import type HTTPChannel from "../channel"; export default class BigDB { protected channel: HTTPChannel; protected queuedSaves: any[]; constructor(channel: HTTPChannel); /** * Creates a new database object in the given table with the specified key. If no key is specified (null), the object will receive an autogenerated id. * @param table The name of the table to create the database object in. * @param key The key to assign to the database object. * @param obj he database object to create in the table. */ createObject(table: string, key: string, obj: any): Promise; /** * Loads the database object corresponding to the player from the PlayerObjects table. */ loadMyPlayerObject(): Promise; /** * Load the database object with the given key from the given table. * @param table The table to load the database object from. * @param key The key of the database object to load. */ load(table: string, key: string): Promise; /** * Loads the database objects with the given keys from the given table. * @param table The table to load the database objects from. * @param keys The keys of the database objects to load. * @returns */ loadKeys(table: string, keys: string[]): Promise<(DatabaseObject | null)[]>; /** * Loads or creates the database object with the given key from the given table. * @param table The table from which to load or create the database object * @param key The key of the database object to load or create */ loadOrCreate(table: string, key: string): Promise; /** * Delete a set of database objects from a table. * @param table The table to delete the database objects from. * @param keys The keys of the database objects to delete. */ deleteKeys(table: string, keys: string[]): Promise; /** * Loads or creates database objects with the given keys from the given table. New objects are created if there are no existing objects for the given keys. * @param table The table from which to load or create the database objects. * @param keys The keys of the database objects to load or create. */ loadKeysOrCreate(table: string, keys: string[]): Promise; /** * Load a database object from a table using the specified index. * @param table The table to load the database object from. * @param index The name of the index to query for the database object. * @param indexValue An array of objects of the same types as the index properties, specifying which object to load. */ loadSingle(table: string, index: string, indexValue?: any): Promise | null>; /** * Load a range of database objects from a table using the specified index. * @param table The table to load the database objects from. * @param index The name of the index to query for the database objects. * @param indexPath Where in the index to start the range search: An array of objects of the same types as the index properties, specifying where in the index to start loading database objects from. For instance, in the index [Mode,Map,Score] you might use new object[]{"expert","skyland"} as the indexPath and use the start and stop arguments to determine the range of scores you wish to return. IndexPath can be set to null if there is only one property in the index. * @param start Where to start the range search. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then start defines the minimum score to include in the results. * @param stop Where to stop the range search. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then stop defines the maximum score to include in the results. * @param limit The max amount of objects to return. */ loadRange(table: string, index: string, indexPath?: any[], start?: any, stop?: any, limit?: number): Promise<(DatabaseObject | null)[]>; /** * Delete a range of database objects from a table using an index. * @param table The table to delete the database object from. * @param index The name of the index to query for the database objects to delete. * @param indexPath Where in the index to start the range delete: An array of objects of the same types as the index properties, specifying where in the index to start loading database objects from. For instance, in the index [Mode,Map,Score] you might use new object[]{"expert","skyland"} as the indexPath and use the start and stop arguments to determine the range of scores you wish to delete. IndexPath can be set to null instead of an empty array. * @param start Where to start the range delete. For instance, if the index is [Mode,Map,Score] and indexPath is ["expert","skyland"], then start defines the minimum score to delete. */ deleteRange(table: string, index: string, indexPath: any, start: any, stop: any): Promise; /** * DON'T USE THIS, not fully tested. * Save changes to one or more database objects in one go. * @param {number} useOptimisticLock Should the save only go through, if no other process has modified the object since it was loaded? * @param {number} fullOverwrite Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server. * @param {array} objects The objects with changes to save. * @param {boolean} createIfMissing */ saveChanges(useOptimisticLock: boolean, fullOverwrite: boolean, objects: any[], createIfMissing?: boolean): void; protected startSaves(): void; /** * Because fuck this, it's only for sendinng to pio via the channels so it doesn't matter what people see here. */ protected getIndexValue(values?: any[], extraValue?: any[]): any; } export declare function bigDBDeserialize(properties: any, target: any, isObject: boolean): any; /** * This class represents a database object in BigDB. It contains all the data of the database object, as well * as a method for persisting any changes back to BigDB. */ export declare class DatabaseObject { /** * This is an object, containing all of the values (mapped by their key). * * If typing is important, at least you'll be able to force it? You can use .wrap() on this object in which you must put a Class (not the instance) in the first parameter, that accepts an object for its constructor in its first parameter. * * This is also mutated into the class so you could access it straight away. * * For example: \.dbCurrent.isStaff == true * * Or: \.isStaff == true * */ dbCurrent: T; protected isSaving: boolean; /** * The table of the database object */ table: string; /** * The key of the database object */ key: string; existsInDatabase: boolean; owner: BigDB; createIfMissing: boolean; version: string; constructor(owner: BigDB, table: string, key: string, version: string, createIfMissing: boolean, properties: any); /** * Persist the object to the database, using optimistic locking and full overwrite if specified. * @param {boolean} useOptimisticLocks If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded. * @param {boolean} fullOverwrite Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server. */ save(useOptimisticLocks: boolean, fullOverwrite: boolean): void; _internal_(method: "get-table" | "get-key" | "get-version"): string; _internal_(method: "get-is-saving"): boolean; _internal_(method: "get-dbCurrent"): T; _internal_(method: "set-is-saving" | "set-version" | "change-dbCurrent"): void; }