The JavaScript Database, for Node.js, nw.js, electron and the browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
nedb/docs/storage.md

13 KiB

storage

Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) For a react-native database, we use @react-native-async-storage/async-storage

This version is the Node.js/Node Webkit version It's essentially fs, mkdirp and crash safe write and read functions

storage.exists(file, cb)

Callback returns true if file exists

Kind: static method of storage

Param Type
file string
cb existsCallback

storage.existsAsync(file) ⇒ Promise.<boolean>

Returns Promise if file exists

Kind: static method of storage

Param Type
file string

storage.rename(oldPath, newPath, c) ⇒ void

Node.js' fs.rename

Kind: static method of storage

Param Type
oldPath string
newPath string
c NoParamCallback

storage.renameAsync(oldPath, newPath) ⇒ Promise.<void>

Node.js' fs.promises.rename

Kind: static method of storage

Param Type
oldPath string
newPath string

storage.writeFile(path, data, options, callback)

Node.js' fs.writeFile

Kind: static method of storage

Param Type
path string
data string
options object
callback function

storage.writeFileAsync(path, data, [options]) ⇒ Promise.<void>

Node.js' fs.promises.writeFile

Kind: static method of storage

Param Type
path string
data string
[options] object

storage.writeFileStream(path, [options]) ⇒ fs.WriteStream

Node.js' fs.createWriteStream

Kind: static method of storage

Param Type
path string
[options] Object

Node.js' fs.unlink

Kind: static method of storage

Param Type
path string
callback function

storage.unlinkAsync(path) ⇒ Promise.<void>

Node.js' fs.promises.unlink

Kind: static method of storage

Param Type
path string

storage.appendFile(path, data, options, callback)

Node.js' fs.appendFile

Kind: static method of storage

Param Type
path string
data string
options object
callback function

storage.appendFileAsync(path, data, [options]) ⇒ Promise.<void>

Node.js' fs.promises.appendFile

Kind: static method of storage

Param Type
path string
data string
[options] object

storage.readFile(path, options, callback)

Node.js' fs.readFile

Kind: static method of storage

Param Type
path string
options object
callback function

storage.readFileAsync(path, [options]) ⇒ Promise.<Buffer>

Node.js' fs.promises.readFile

Kind: static method of storage

Param Type
path string
[options] object

storage.readFileStream(path, [options]) ⇒ fs.ReadStream

Node.js' fs.createReadStream

Kind: static method of storage

Param Type
path string
[options] Object

storage.mkdir(path, options, callback)

Node.js' fs.mkdir

Kind: static method of storage

Param Type
path string
options object
callback function

storage.mkdirAsync(path, options) ⇒ Promise.<(void|string)>

Node.js' fs.promises.mkdir

Kind: static method of storage

Param Type
path string
options object

storage.ensureFileDoesntExistAsync(file) ⇒ Promise.<void>

Kind: static method of storage

Param Type
file string

storage.ensureFileDoesntExist(file, callback)

Kind: static method of storage

Param Type
file string
callback NoParamCallback

storage.flushToStorage(options, callback)

Flush data in OS buffer to storage if corresponding option is set

Kind: static method of storage

Param Type Default Description
options object | string

If options is a string, it is assumed that the flush of the file (not dir) called options was requested

[options.filename] string
[options.isDir] boolean false

Optional, defaults to false

callback NoParamCallback

storage.flushToStorageAsync(options) ⇒ Promise.<void>

Flush data in OS buffer to storage if corresponding option is set

Kind: static method of storage

Param Type Default Description
options object | string

If options is a string, it is assumed that the flush of the file (not dir) called options was requested

[options.filename] string
[options.isDir] boolean false

Optional, defaults to false

storage.writeFileLines(filename, lines, callback)

Fully write or rewrite the datafile

Kind: static method of storage

Param Type
filename string
lines Array.<string>
callback NoParamCallback

storage.writeFileLinesAsync(filename, lines) ⇒ Promise.<void>

Fully write or rewrite the datafile

Kind: static method of storage

Param Type
filename string
lines Array.<string>

storage.crashSafeWriteFileLines(filename, lines, [callback])

Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)

Kind: static method of storage

Param Type Description
filename string
lines Array.<string>
[callback] NoParamCallback

Optional callback, signature: err

storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒ Promise.<void>

Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)

Kind: static method of storage

Param Type
filename string
lines Array.<string>

storage.ensureDatafileIntegrity(filename, callback)

Ensure the datafile contains all the data, even if there was a crash during a full file write

Kind: static method of storage

Param Type Description
filename string
callback NoParamCallback

signature: err

storage.ensureDatafileIntegrityAsync(filename) ⇒ Promise.<void>

Ensure the datafile contains all the data, even if there was a crash during a full file write

Kind: static method of storage

Param Type
filename string

storage~existsCallback : function

Kind: inner typedef of storage

Param Type
exists boolean