Page cover

databaseCustom Database

Utility.db allows you to manage your database system (Addons Developer)

Utility.db.createTable('table', { data })
await Utility.db.insert('table', { data }); // Insert new data into the database
await Utility.db.update('table', { newData }, { conditions }); // Update existing data in the table
await Utility.db.findAll('table'); // Find all data in the table
await Utility.db.findOne('table', { conditions }); // Find specific data in the table
await Utility.db.delete('table', { conditions }); // Delete existing data from the table

EXAMPLE

// Create a new table with columns 'id' and 'age'
await Utility.db.createTable('users', { id: "TEXT PRIMARY KEY", name: "TEXT", age: "INTEGER" });

// Insert data if it doesn't exist
await Utility.db.insert('users', { id: 'simon', name: 'Simon', age: 50 });

// Update existing data in the table
await Utility.db.update('users', { age: 51 }, { id: 'simon' });

// Find all data in the table
const allUsers = await Utility.db.findAll('users');

// Find specific data in the table based on conditions
const user = await Utility.db.findOne('users', { id: 'simon' });

// Delete specific data from the table based on conditions
await Utility.db.delete('users', { id: 'simon' });

Last updated