Module

x/denodb/lib/database.ts>Database

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Latest
class Database
import { Database } from "https://dotland.deno.dev/x/denodb@v1.4.0/lib/database.ts";

Database client which interacts with an external database instance.

Constructors

new
Database(dialectOptionsOrDatabaseOptionsOrConnector: DatabaseOptions, connectionOptions?: ConnectorOptions)

Initialize database given a dialect and options.

Current Usage: const db = new Database(new SQLite3Connector({ filepath: "./db.sqlite" }));

const db = new Database({
  connector: new SQLite3Connector({ ... }),
  debug: true
});

Dialect usage: const db = new Database("sqlite3", { filepath: "./db.sqlite" });

const db = new Database({
  dialect: "sqlite3",
  debug: true
}, { ... });

Properties

private
_connector: Connector
private
_debug: boolean
private
_models: ModelSchema[]
private
_queryBuilder: QueryBuilder
private
_translator: Translator

Methods

_computeModelFieldMatchings(
table: string,
fields: ModelFields,
withTimestamps: boolean,
): { toClient: FieldMatchingTable; toDatabase: FieldMatchingTable; }

Compute field matchings tables for model usage.

Close the current database connection.

Get the database dialect.

Test database connection.

query(query: QueryDescription): Promise<Model | Model[]>

Pass on any query to the database.

await db.query("SELECT * FROM `flights`");
sync(options?: SyncOptions)

Create the given models in the current database.

await db.sync({ drop: true });
transaction(queries: () => Promise<void>)

Execute queries within a transaction.

Static Methods

private
_convertDialectFormToConnectorForm(
dialectOptionsOrDatabaseOptions: DialectDatabaseOptions,
connectionOptions: ConnectorOptions,
fromConstructor?,
): ConnectorDatabaseOptions
private
_isInDialectForm(dialectOptionsOrDatabaseOptions: DatabaseOptions): boolean
forDialect(dialectOptionsOrDatabaseOptions: Omit<DialectDatabaseOptions, "disableDialectUsageDeprecationWarning">, connectionOptions: ConnectorOptions): Database