Local MySQL

The Local Database module provides a simple interface for interacting with SQLite databases. It supports both in-memory and file-based databases, allowing for flexible data storage options.

Constructor

The constructor initializes a new instance of the sql class, allowing you to specify whether to use an in-memory database or a file-based database.

constructor(location: boolean | string);
parameter
description

location

A boolean for an in-memory database (true), or a string for a file-based database (specifying the database filename without the extension).

Methods

get

Returns the SQLite database instance.

public get get(): sqlite3.Database | null;

query

Executes a SQL query with optional parameters.

public query<T>(query: string, params: any[] = []): Promise<T[]>;
parameter
description

query

The SQL query to execute.

params

Optional parameters for the SQL query.ms

refresh

Refreshes the SQLite database connection.

File-Based Example

Here’s how you can use the sql class to create a database and execute a query:

In-Memory Database Example

To create an in-memory database, simply pass true to the constructor:

Last updated