Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.32 KB

altering-data.md

File metadata and controls

54 lines (41 loc) · 1.32 KB

Updating data

vlquery can save your data too!

Creating records

Let's create a simple book with a refrence to its author

const author = await db.author.find("<uuid>");

const book = new Book();
book.title = "My First Book!";
book.author = author;

await book.create();

Alternatively to using .author you could do this:

book.authorId = "<uuid>";

vlquery will add the new id of your record to it, so after calling create, you'll be able to use the new id!

Updating existing records

Whenever your data need some refreshing, do this:

const book = await db.book.find("<uuid>");
book.title = "New Title";

await book.update();

Deleting a record

When your data is no longer required, it can be deleted with this code. vlquery will check all references before you can delete the item!

const book = await db.book.find("<uuid>");
await book.delete();

If you are using an active column, this will only deactivate the row!

Duplicating a record

Records can be duplicated by using the createDuplicate method on an entity

const book = await db.book.find("<uuid>");

const copy = book.createDuplicate();
copy.title += " (Copy)";
await copy.create();

console.log(book.title); // "My first book"
console.log(copy.title) // "My first book (Copy)"