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

Query models

Once we have all the models created, we can easily query them.

Using query builder

Query builder allows you to generate queries using only simple, abstract methods.

More information about available methods can be found in Model methods.

Here is a list of examples:

await Flight.create([
  {
    departure: 'Paris',
    destination: 'Tokyo',
  },
  {
    departure: 'London',
    destination: 'San Francisco',
  },
]);

await Flight.select('destination').all();
// [ { destination: "Tokyo" }, { destination: "San Francisco" } ]

await Flight.where('destination', 'Tokyo').delete();

await Flight.all();
// [
//  {
//    id: 2,
//    departure: "London",
//    destination: "San Francisco",
//    flightDuration: 2.5,
//    created_at: 2020-05-17T13:16:32.333Z,
//    updated_at: 2020-05-17T13:16:32.333Z
//   }
// ]

await Flight.select('destination').find('2');
// [ { destination: "San Francisco" } ]

await Flight.count();
// 1

await Flight.select('id', 'destination').orderBy('id').get();
// [ { id: "2", destination: "San Francisco" } ]

Using model records

You can also create, update and delete model records by using the model record itself.

More information about using model records can be found in Model records.

const flight = new Flight();
flight.departure = 'Dublin';
flight.destination = 'Paris';
flight.flightDuration = 3;
await flight.save();

flight.departure = 'Tokyo';
await flight.update();

await flight.delete();
Last updated on 1/2/2021 by eveningkid
← Synchronize databaseTransactions →
  • Using query builder
  • Using model records
Docs
Getting StartedAPI Reference
More
GitHubStar