You can add data to your mock server by accessing vroom.db
on your created instance.
const vroom = createVroom({
models: {...},
server: {
enable: true,
}
})
vroom.db.todo.create({
title: 'Buy milk',
completed: false
})
Each item you create in the db will automatically get an unique id
based on you id settings.
Adding relationships is done by setting the id of one side of the relationsship. Vroom will automatically update the inverse relationship.
Given the following models
typescriptconst models = {
book: defineModel({
schema: {
title: { type: String },
},
belongsTo: {
author: () => "author",
},
}),
author: defineModel({
schema: {
name: { type: String },
},
hasMany: {
books: () => "book",
},
}),
};
We can create some relations like this
typescriptconst grrm = db.author.create({ name: "George R. R. Martin" });
// Give the author
db.book.create({ title: "A Game of Thrones", author: grrm });
// Or the id directly
db.book.create({ title: "A Clash of Kings", authorId: grrm.id });
const hobbit = db.book.create({ title: "The Hobbit" });
const lotr = db.book.create({ title: "The Lord of the Rings" });
db.author.create({ name: "J.R.R. Tolkien", books: [hobbit, lotr] });
You can also shortcut this process like so:
typescriptdb.author.create({
name: "George R. R. Martin",
books: db.book.createMany(
{ title: "A Game of Thrones" },
{ title: "A Clash of Kings" },
),
});
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4