denoDB

denoDB

  • Docs
  • GitHub
  • Help

›Guides

Guides

  • Getting started
  • Connect to a database
  • Clients

    • Using MariaDB
    • Using MongoDB
    • Using MySQL
    • Using PostgreSQL
    • Using SQLite
  • Create models
  • Synchronize database
  • Query models
  • Transactions
  • Relationships

    • Foreign key
    • One-to-one
    • One-to-many
    • Many-to-many
  • Model events

API Reference

    Models

    • Data types
    • Field descriptors
    • Model methods
    • Model records

Synchronize database

Before creating our models, we need to both link and synchronize them to our database.

Link models

Linking our models is very straight-forward. Use db.link with every model you have created:

const db = new Database(...);

// Put or import your models before linking them
class Business extends Model { ... }

db.link([Business]);

In case of pivot models created with Relationships.manyToMany, it is good practice to put them first:

const BusinessOwner = Relationships.manyToMany(Business, Owner);

db.link([BusinessOwner, Business, Owner]);

Synchronize models

Synchronizing your models means making sure your models are available in the provided database. If they do not exist, synchronizing will create them.

db.sync();

Some of these tables might have values already and so you might want to drop them:

db.sync({ drop: true });

This will drop every model previously put into db.link(models).

Last updated on 1/2/2021 by eveningkid
← Create modelsQuery models →
  • Link models
  • Synchronize models
Docs
Getting StartedAPI Reference
More
GitHubStar