{"id":19237968,"url":"https://github.com/svtslv/nestjs-knex","last_synced_at":"2025-05-01T09:54:18.671Z","repository":{"id":40935051,"uuid":"243845272","full_name":"svtslv/nestjs-knex","owner":"svtslv","description":"Knex module for Nest","archived":false,"fork":false,"pushed_at":"2024-06-16T10:47:07.000Z","size":715,"stargazers_count":65,"open_issues_count":8,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-01T09:54:10.353Z","etag":null,"topics":["database","knex","nest","nestjs","orm"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svtslv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-28T20:05:04.000Z","updated_at":"2024-05-19T07:38:56.000Z","dependencies_parsed_at":"2024-06-18T15:36:34.193Z","dependency_job_id":null,"html_url":"https://github.com/svtslv/nestjs-knex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svtslv%2Fnestjs-knex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svtslv%2Fnestjs-knex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svtslv%2Fnestjs-knex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svtslv%2Fnestjs-knex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svtslv","download_url":"https://codeload.github.com/svtslv/nestjs-knex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251856993,"owners_count":21655119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","knex","nest","nestjs","orm"],"created_at":"2024-11-09T16:28:52.188Z","updated_at":"2025-05-01T09:54:18.650Z","avatar_url":"https://github.com/svtslv.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS Knex\n\n\u003ca href=\"https://www.npmjs.com/package/nestjs-knex\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/nestjs-knex.svg\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/nestjs-knex\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/nestjs-knex.svg\" alt=\"Package License\" /\u003e\u003c/a\u003e\n\n## Table of Contents\n\n- [Description](#description)\n- [Installation](#installation)\n- [Examples](#examples)\n- [License](#license)\n\n## Description\nIntegrates Knex with Nest\n\n## Installation\n\n```bash\nnpm install nestjs-knex knex\n```\n\nYou can also use the interactive CLI\n\n```sh\nnpx nestjs-modules\n```\n\n## Examples\n```bash\nnpm install nestjs-knex knex sqlite3\n```\n\n### KnexModule.forRoot(options, connection?)\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { KnexModule } from 'nestjs-knex';\nimport { AppController } from './app.controller';\n\n@Module({\n  imports: [\n    KnexModule.forRoot({\n      config: {\n        client: \"sqlite3\",\n        useNullAsDefault: true,\n        connection: ':memory:',\n      },\n    }),\n  ],\n  controllers: [AppController],\n})\nexport class AppModule {}\n```\n\n### KnexModule.forRootAsync(options, connection?)\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { KnexModule } from 'nestjs-knex';\nimport { AppController } from './app.controller';\n\n@Module({\n  imports: [\n    KnexModule.forRootAsync({\n      useFactory: () =\u003e ({\n        config: {\n          client: \"sqlite3\",\n          useNullAsDefault: true,\n          connection: ':memory:',\n        },\n      }),\n    }),\n  ],\n  controllers: [AppController],\n})\nexport class AppModule {}\n```\n\n### InjectKnex(connection?)\n\n```ts\nimport { Controller, Get, } from '@nestjs/common';\nimport { InjectKnex, Knex } from 'nestjs-knex';\n\n@Controller()\nexport class AppController {\n  constructor(\n    @InjectKnex() private readonly knex: Knex,\n  ) {}\n\n  @Get()\n  async getHello() {\n    if (!await this.knex.schema.hasTable('users')) {\n      await this.knex.schema.createTable('users', table =\u003e {\n        table.increments('id').primary();\n        table.string('name');\n      });\n    }\n    await this.knex.table('users').insert({ name: 'Name' });\n    const users = await this.knex.table('users');\n    return { users };\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvtslv%2Fnestjs-knex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvtslv%2Fnestjs-knex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvtslv%2Fnestjs-knex/lists"}