A set of tools and utilities to simplify the development of Auth0 Extensions for Postgres.
const tools = require('auth0-extension-postgres-tools');
A record provider exposes CRUD capabilities which makes it easy to interact with records from an Extension (eg: delete a record, update a record, ...). Depending on the underlying storage you may or may not have support for concurrency.
const db = new tools.PostgresRecordProvider('postgresql://dbuser:[email protected]:5432/database-name');
db.getRecords('documents')
.then(function (documents) {
console.log('All documents:', documents);
});
db.getRecord('documents', '12345')
.then(function (doc) {
console.log('Document:', doc);
});
db.create('documents', { name: 'my-foo.docx' })
.then(function (doc) {
console.log('Document:', doc);
});
db.create('documents', { _id: 'my-custom-id', name: 'my-foo.docx' })
.then(function (doc) {
console.log('Document:', doc);
});
// Update document with id 1939393
db.update('documents', 1939393, { name: 'my-foo.docx' })
.then(function (doc) {
console.log('Document:', doc);
});
// Update document with id 1939393. If it doesn't exist, create it (upsert).
const upsert = true;
db.update('documents', 1939393, { name: 'my-foo.docx' }, upsert)
.then(function (doc) {
console.log('Document:', doc);
});
db.delete('documents', 1939393)
.then(function(hasBeenDeleted) {
});