Class Collection - Trebossalol/localdb GitHub Wiki
A collection is a list, which holds objects which look the same. In this example down below we'll create a collection which holds users.
class Collection<DocType = DocumentLike>
Create a collection using your user interface
interface User {
username: string
coins: number
}
const accounts = new Collection<User>('accounts', {
// Options
})
folderPath
:string
- A path to a folder, where all collection details should be stored (note: This will be automatically specified by yourDatabase
instance!)
normalize
:(document) => string
- A callback which will normalize the output json string (default:(doc) => JSON.stringify(doc, null, 3)
)
docIdGenerator
:(document) => string
- A callback which must generate a uniqe ID for every document (default:(_doc) => (Math.random() * (999999 - 111111) + 111111).toString()
)
fileNameGenerator
:(collection) => string
- A callback which will generate the filename of the collection (note: This will be automatically specified by yourDatabase
instance!)
onErrorBehaviour
:string
- A string which specifies the behaviour of the collection if an error occuesCREATE_BACKUP_AND_OVERWRITE
-> Creates a backup of the error-version and creates a new empty collectionOVERWRITE
-> Overwrites the error-version to an empty collection (Data will be lost!)LOG_ERROR
-> Throws an exceptionundefined
->LOG_ERROR
onRestartBehaviour
:string
- A string which specifies the behaviour of the collection on initOVERWRITE
-> Overwrites the collection (Data will be lost!)undefined
-> Normal behaviour
You can see every method here, or in your prefered code editor, because this library has almost fully typescript support!