Methods
(static) create(data) → {Promise.<Boolean>}
- Source:
Create A Record In Customer Database
Example
// Create a record
try {
var data = {name: 'XYZ', age: 24}
var myDatabase = this.database('customer')
await myDatabase.create(data)
} catch (err) {
// Error
}
Parameters:
Name | Type | Description |
---|---|---|
data |
Object |
Returns:
Validation Success or Failure
- Type
- Promise.<Boolean>
(static) delete(id) → {Promise.<Boolean>}
- Source:
// Delete a record by id
Example
try {
var myDatabase = this.database('customer')
var id = 24
var res = await myDatabase.delete(id)
// Returns Success
} catch (err) {
// Error
}
Parameters:
Name | Type | Description |
---|---|---|
id |
Number |
Returns:
Validation Success or Failure
- Type
- Promise.<Boolean>
(static) list() → {Array}
- Source:
Get All The Records From Database This is a database function in page.js.
Example
// Get all the records from a database 'customer'
try {
var myDatabase = this.database('customer')
var res = await myDatabase.list()
// Returns all the records as array of objects (key-value pair)
} catch (err) {
// Error
}
Returns:
If Success returns Database Records or Failure
- Type
- Array
(static) read(id) → {Object}
- Source:
Read a record, by an id
Example
try {
var myDatabase = this.database('customer')
var id = 24
var res = await myDatabase.read(id)
// Returns Response Object - {id: 24, name: 'Customer 1', age: 28, country: 'England'}
} catch (err) {
// Error
}
Parameters:
Name | Type | Description |
---|---|---|
id |
Number |
Returns:
- Type
- Object
(static) update(id, updatedData) → {Promise.<Boolean>}
- Source:
Update a record
Example
try {
var myDatabase = this.database('customer')
var updatedData = {id: 24, name: 'XYZ-1'}
await myDatabase.update(updatedData.id, updatedData)
} catch (err) {
// Error
}
this.database('customer').update(updatedData.id, updatedData)
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Record Id |
updatedData |
Object | key-value pair |
Returns:
Validation Success or Failure
- Type
- Promise.<Boolean>