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

Transactions

Transactions are helpful to run a list of inter-dependent queries that could potentially break. If one doesn't work, it shouldn't impact the others and roll back the previous queries.

Any query that goes inside a transaction block, will only be run if all of them have been successfully executed.

Transactions are supported on MySQL, MariaDB, SQLite and Postgres (not MongoDB).

const db = new Database(connection);

// Declare your models and link them to your database

await db.transaction(async () => {
  const user = await User.create({ name: 'Joelle' });
  await Payments.create({ userId: user.id, amount: 20 });
});

Just to make sure it's all clear for you: if User.create or Payments.create fails, this whole block will be dismissed and it will be as if nothing had happened.

Last updated on 4/19/2021 by eveningkid
← Query modelsForeign key →
Docs
Getting StartedAPI Reference
More
GitHubStar