@types/nedb
- Version 1.8.16
- Published
- 14 kB
- 1 dependency
- MIT license
Install
npm i @types/nedb
yarn add @types/nedb
pnpm add @types/nedb
Overview
TypeScript definitions for nedb
Index
Classes
Nedb
- addListener()
- addToIndexes()
- count()
- ensureIndex()
- find()
- findOne()
- getAllData()
- getCandidates()
- insert()
- listenerCount()
- listeners()
- loadDatabase()
- off()
- on()
- once()
- persistence
- prependListener()
- prependOnceListener()
- rawListeners()
- remove()
- removeFromIndexes()
- removeIndex()
- removeListener()
- resetIndexes()
- update()
- updateIndexes()
Interfaces
Classes
class Nedb
class Nedb<G = any> extends EventEmitter {}
constructor
constructor(pathOrOptions?: string | Nedb.DataStoreOptions);
property persistence
persistence: Nedb.Persistence;
method addListener
addListener: (event: 'compaction.done', listener: () => void) => this;
method addToIndexes
addToIndexes: <T extends G>(doc: T | T[]) => void;
Add one or several document(s) to all indexes
method count
count: { (query: any, callback: (err: Error | null, n: number) => void): void; (query: any): Nedb.CursorCount;};
Count all documents matching the query
Parameter query
MongoDB-style query
method ensureIndex
ensureIndex: ( options: Nedb.EnsureIndexOptions, cb?: (err: Error | null) => void) => void;
Ensure an index is kept for this field. Same parameters as lib/indexes For now this function is synchronous, we need to test how much time it takes We use an async API for consistency with the rest of the code
Parameter cb
Optional callback, signature: err
method find
find: { <T extends G>( query: any, projection: any, callback: (err: Error | null, documents: T[]) => void ): void; <T extends G>(query: any, projection?: any): Nedb.Cursor<T>; <T extends G>( query: any, callback: (err: Error, documents: T[]) => void ): void;};
Find all documents matching the query If no callback is passed, we return the cursor so that user can limit, skip and finally exec
Parameter query
MongoDB-style query
Parameter projection
MongoDB-style projection
Find all documents matching the query If no callback is passed, we return the cursor so that user can limit, skip and finally exec *
Parameter query
MongoDB-style query
method findOne
findOne: { <T extends G>( query: any, projection: any, callback: (err: Error | null, document: T) => void ): void; <T extends G>(query: any, callback: (err: Error, document: T) => void): void;};
Find one document matching the query
Parameter query
MongoDB-style query
Parameter projection
MongoDB-style projection
Find one document matching the query
Parameter query
MongoDB-style query
method getAllData
getAllData: () => any[];
Get an array of all the data in the database
method getCandidates
getCandidates: (query: any) => void;
Return the list of candidates for a given query Crude implementation for now, we return the candidates given by the first usable index if any We try the following query types, in this order: basic match, $in match, comparison match One way to make it better would be to enable the use of multiple indexes if the first usable index returns too much data. I may do it in the future.
TODO: needs to be moved to the Cursor module
method insert
insert: { <T extends G>( newDoc: T, cb?: (err: Error | null, document: T) => void ): void; <T extends G>(newDocs: T[], cb?: (err: Error, documents: T[]) => void): void;};
Insert one or more new documents
Parameter cb
Optional callback, signature: err, insertedDoc
method listenerCount
listenerCount: (type: 'compaction.done') => number;
method listeners
listeners: (event: 'compaction.done') => Array<() => void>;
method loadDatabase
loadDatabase: (cb?: (err: Error | null) => void) => void;
Load the database from the datafile, and trigger the execution of buffered commands if any
method off
off: (event: 'compaction.done', listener: () => void) => this;
method on
on: (event: 'compaction.done', listener: () => void) => this;
method once
once: (event: 'compaction.done', listener: () => void) => this;
method prependListener
prependListener: (event: 'compaction.done', listener: () => void) => this;
method prependOnceListener
prependOnceListener: (event: 'compaction.done', listener: () => void) => this;
method rawListeners
rawListeners: (event: 'compaction.done') => Array<() => void>;
method remove
remove: { ( query: any, options: Nedb.RemoveOptions, cb?: (err: Error | null, n: number) => void ): void; (query: any, cb?: (err: Error, n: number) => void): void;};
Remove all docs matching the query For now very naive implementation (similar to update)
Parameter options
Optional options options.multi If true, can update multiple documents (defaults to false)
Parameter cb
Optional callback, signature: err, numRemoved
private Use Datastore.remove which has the same signature
method removeFromIndexes
removeFromIndexes: <T extends G>(doc: T | T[]) => void;
Remove one or several document(s) from all indexes
method removeIndex
removeIndex: (fieldName: string, cb?: (err: Error | null) => void) => void;
Remove an index
Parameter cb
Optional callback, signature: err
method removeListener
removeListener: (event: 'compaction.done', listener: () => void) => this;
method resetIndexes
resetIndexes: (newData: any) => void;
Reset all currently defined indexes
method update
update: { ( query: any, updateQuery: any, options?: Nedb.UpdateOptions, cb?: ( err: Error | null, numberOfUpdated: number, upsert: boolean ) => void ): void; <T extends G>( query: any, updateQuery: any, options?: Nedb.UpdateOptions, cb?: ( err: Error, numberOfUpdated: number, affectedDocuments: any, upsert: boolean ) => void ): void;};
Update all docs matching query v1.7.4 and prior signature. For now, very naive implementation (recalculating the whole database)
Parameter options
Optional options options.multi If true, can update multiple documents (defaults to false) options.upsert If true, document is inserted if the query doesn't match anything
Parameter cb
Optional callback, signature: err, numReplaced, upsert (set to true if the update was in fact an upsert)
private Use Datastore.update which has the same signature
Update all docs matching query v1.8 signature. For now, very naive implementation (recalculating the whole database)
Parameter options
Optional options options.multi If true, can update multiple documents (defaults to false) options.upsert If true, document is inserted if the query doesn't match anything
Parameter cb
Optional callback, signature: err, numAffected, affectedDocuments (when returnUpdatedDocs is set to true), obj or array upsert (set to true if the update was in fact an upsert)
private Use Datastore.update which has the same signature
method updateIndexes
updateIndexes: { <T extends G>(oldDoc: T, newDoc: T): void; <T extends G>(updates: { oldDoc: T; newDoc: T }[]): void;};
Update one or several documents in all indexes To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs If one update violates a constraint, all changes are rolled back
Interfaces
interface Cursor
interface Cursor<T> {}
method exec
exec: (callback: (err: Error | null, documents: T[]) => void) => void;
method limit
limit: (n: number) => Cursor<T>;
method projection
projection: (query: any) => Cursor<T>;
method skip
skip: (n: number) => Cursor<T>;
method sort
sort: (query: any) => Cursor<T>;
interface CursorCount
interface CursorCount {}
method exec
exec: (callback: (err: Error | null, count: number) => void) => void;
interface DataStoreOptions
interface DataStoreOptions {}
property autoload
autoload?: boolean | undefined;
property corruptAlertThreshold
corruptAlertThreshold?: number | undefined;
property filename
filename?: string | undefined;
property inMemoryOnly
inMemoryOnly?: boolean | undefined;
property nodeWebkitAppName
nodeWebkitAppName?: boolean | undefined;
property timestampData
timestampData?: boolean | undefined;
method afterSerialization
afterSerialization: (line: string) => string;
method beforeDeserialization
beforeDeserialization: (line: string) => string;
method onload
onload: (error: Error | null) => any;
interface EnsureIndexOptions
interface EnsureIndexOptions {}
property expireAfterSeconds
expireAfterSeconds?: number | undefined;
property fieldName
fieldName: string;
property sparse
sparse?: boolean | undefined;
property unique
unique?: boolean | undefined;
interface Persistence
interface Persistence {}
method compactDatafile
compactDatafile: () => void;
method setAutocompactionInterval
setAutocompactionInterval: (interval: number) => void;
method stopAutocompaction
stopAutocompaction: () => void;
interface RemoveOptions
interface RemoveOptions {}
options only one option for now: multi which allows the removal of multiple documents if set to true. Default is false
property multi
multi?: boolean | undefined;
interface UpdateOptions
interface UpdateOptions {}
multi (defaults to false) which allows the modification of several documents if set to true upsert (defaults to false) if you want to insert a new document corresponding to the update rules if your query doesn't match anything
property multi
multi?: boolean | undefined;
property returnUpdatedDocs
returnUpdatedDocs?: boolean | undefined;
property upsert
upsert?: boolean | undefined;
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/nedb
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/nedb)
- HTML<a href="https://www.jsdocs.io/package/@types/nedb"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2970 ms. - Missing or incorrect documentation? Open an issue for this package.