A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://frederikbache.github.io/vue-vroom/guide/server/seeding.html below:

Website Navigation


Seeding data | Vue goes Vroom

Seeding data #

You can add data to your mock server by accessing vroom.db on your created instance.

typescript
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.

Seeding relations #

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

typescript
const 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

typescript
const 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:

typescript
db.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