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

nestjs-knex

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-knex

Nest - modern, fast, powerful node.js web framework (@knex)

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NestJS Knex

NPM Version Package License

Table of Contents

Description

Integrates Knex with Nest

Installation

npm install nestjs-knex knex

You can also use the interactive CLI

npx nestjs-modules

Examples

npm install nestjs-knex knex sqlite3

KnexModule.forRoot(options, connection?)

import { Module } from '@nestjs/common';
import { KnexModule } from 'nestjs-knex';
import { AppController } from './app.controller';

@Module({
  imports: [
    KnexModule.forRoot({
      config: {
        client: "sqlite3",
        useNullAsDefault: true,
        connection: ':memory:',
      },
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

KnexModule.forRootAsync(options, connection?)

import { Module } from '@nestjs/common';
import { KnexModule } from 'nestjs-knex';
import { AppController } from './app.controller';

@Module({
  imports: [
    KnexModule.forRootAsync({
      useFactory: () => ({
        config: {
          client: "sqlite3",
          useNullAsDefault: true,
          connection: ':memory:',
        },
      }),
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

InjectKnex(connection?)

import { Controller, Get, } from '@nestjs/common';
import { InjectKnex, Knex } from 'nestjs-knex';

@Controller()
export class AppController {
  constructor(
    @InjectKnex() private readonly knex: Knex,
  ) {}

  @Get()
  async getHello() {
    if (!await this.knex.schema.hasTable('users')) {
      await this.knex.schema.createTable('users', table => {
        table.increments('id').primary();
        table.string('name');
      });
    }
    await this.knex.table('users').insert({ name: 'Name' });
    const users = await this.knex.table('users');
    return { users };
  }
}

License

MIT

Keywords

FAQs

Package last updated on 18 Apr 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