First, let's start off with something simple! You have a database called customers with the columns name, mail, ordersArray. Now you want to add a customer. You can do that with the table.add function. Here are two examples.
// First, let's make the array of the order.let orders = [1,5,9];// Now add it to the table.awaittable.add(["Paul","paul@example.mail", orders]);// Done!
// First, let's make the array of the orderlet orders = [1,5,9];// Now add it to the databasetable.add(["Paul","paul@example.mail", orders]).then(() => {// Done!});
Updating
Now, the customer ordered product number three. Then you want to add that to the array. You can do that with the table.update function.
// First, let's get the customer informationlet filter =newclient.filter(1)filter.add("name","Paul");let customer =awaittable.where(filter);// Now, get the array, add order number two and sort it (because we can)let orderArray =customer.orderArray;orderArray.push(2);orderArray.sort();// Now, let's update the databaseawaittable.update(filter, {column:"ordersArray", value: orderArray});// Array updated!
// First, let's get the customer informationlet filter =newclient.filter(1)filer.add("name","Paul");table.where(filter).then(customer => {// Now, get the array, add order number two and sort it (because we can)let orderArray =customer.orderArray;orderArray.push(2);orderArray.sort();// Now, let's update the databasetable.update(filter, {column:"ordersArray", value: orderArray}).then(() => {// Array updated! });});
Ensure
If you want to add a row if something in it doesn't exists, you can do that with the table.ensure function. Here is a example.
let filter =newclient.filter();filter.add("name","Jan");let res =awaittable.ensure(filter, ["Paul","paul@example.com","password"]);// Use the variable "res" with the data.
let filter =newclient.filter();filter.add("name","Jan");table.ensure(filter, ["Paul","paul@example.com","password"]).then(res => {// Use the variable "res" with the data.});
Deleting
Oke, finaly: deleting data! You can delete data with the table.delete function and a filter. Here a example.
let filter =newclient.filter(1)filter.add("name","Paul");awaittable.delete(filter);// Row deleted!
let filter =newclient.filter(1)filter.add("name","Paul");table.delete(filter).then(() => {// Row deleted!});