Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@homeofthings/nestjs-sqlite3

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@homeofthings/nestjs-sqlite3

HomeOfThings - NestJs Sqlite3: Sqlite3 module for NestJs based on 'sqlite3orm'

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Build Status Coverage Status DeepScan grade

PRs Welcome License

HomeOfThings - Sqlite3 for NestJs

This module allows you to map your model, written in JavaScript or TypeScript, to a database schema using SQLite Version 3. nestjs-sqlite3 offers connection pool, automatic upgrades and online backups as well as typesafe database queries and refactoring, using a filter syntax designed to serialize safely without any SQL injection possibility

NOTE: Your contribution is highly welcome! Feel free to pick-up a TODO-item or add yours.

This module is based on sqlite3orm supporting SQLCipher

installation

npm install @homeofthings/nestjs-sqlite3

quick start

import module in AppModule by providing connection options synchronously

@Module({
  imports: [
    Sqlite3Module.register(Sqlite3Module, {file: SQL_MEMORY_DB_SHARED}),
  ],
})
export class AppModule {}

import module in AppModule by providing connection options asynchronously

@Module({
  imports: [
    Sqlite3Module.registerAsync(Sqlite3Module, {
      imports: [], // optional
      useFactory: (): Promise<Sqlite3ModuleOptions> => Promise.resolve({
        // provide your options
      }),
      inject: [], // optional inject params for useFactory method
    }),
  ],
})
export class AppModule {}

inject connection manager

TODO:

get connection

  const connection = await this._connectionManager.getConnection(connectionName);

is using asynchronous context tracking to get the same database connection from the pool throughout the lifetime of a web request or any other asynchronous duration You can create a new context by calling ConnectionManager.createConnectionContext() and close it by calling ConnectionManager.closeConnectionContext(). For web requests this is automatically accomblished by the provided Sqlite3Interceptor.

If you a need for a connection which works independend from the asynchronous context, you can get it from the pool:

  const connection = await this._connectionManager.getConnectionPool(connectionName).get();

inject connection pool

TODO: using InjectConnectionPool decorator

mapping

please see (https://github.com/gms1/node-sqlite3-orm#mapping-intruduction)

inject entity manager

TODO: using InjectEntityManager decorator

inject standard repository

TODO: calling forFeature TODO: using InjectRepository decorator

inject custom repository

TODO: define custom repository class TODO: calling forFeature TODO: using InjectCustomRepository decorator

type safe query syntax

please see (https://github.com/gms1/node-sqlite3-orm#typesafe-query-syntax)

create schema manually

please see (https://github.com/gms1/node-sqlite3-orm#schema-creation)

ceeate/upgrade schema automatically

TODO

  const connection = await this._connectionManager.getConnection(connectionName);
  const autoUpgrader = new AutoUpgrader(connection);

  // run autoupgrade for all registered tables
  autoUpgrader.upgradeAllTables();

  // run autoupgrade for all tables referenced by a connection:
  autoUpgrader.upgradeTables(ConnectionManager.getTables(connectionName));

NOTE: if you are using a single database, you can call upgradeAllTables, otherwise you will need to specify the tables for the specific database that you want to upgrade. All tables referenced by a forFeature call for a specific database can be retrieved by calling ConnectionManager.getTables

online backup

TODO

  const connection = await this._connectionManager.getConnection(connectionName);
  const backup = await connection.backup('backup.db');
  await backup.step(-1);
  backup.finish();

tracing

TODO

RELEASE NOTES

CHANGELOG

Keywords

FAQs

Package last updated on 08 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc