Registry / database / feathers-knex

feathers-knex

JSON →
library8.0.1jsnpmunverified

A database adapter for Feathers.js that provides a service wrapper around KnexJS, a SQL query builder supporting PostgreSQL, MySQL, SQLite3, MSSQL, MariaDB, and Oracle. Current stable version 8.0.1. This package implements the Feathers Common database adapter API and querying syntax, offering features like pagination, multi-record operations, custom events, and parameterized queries. It requires both `knex` and the corresponding database driver. Released under the Feathers ecosystem, it follows semantic versioning and is actively maintained.

npm install feathers-knex
INSTALL
IMPORT
SIG · FEATHERS-KNEX
F
feathers-knex
databasejavascriptv8.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import service from 'feathers-knex';
✗ const service = require('feathers-knex');
CJS require works for Node, but ESM import is preferred for modern projects.
service (named)
✓ import { service } from 'feathers-knex';
Named export available as an alternative to default.
TypeScript types
✓ import type { Service } from 'feathers-knex';
For TypeScript projects, you can import the Service type for type annotations.

Creates a Feathers app with a Knex-backed messages service using SQLite.

import express from '@feathersjs/express'; import feathers from '@feathersjs/feathers'; import knex from 'knex'; import service from 'feathers-knex'; const app = express(feathers()); const db = knex({ client: 'sqlite3', connection: { filename: './db.sqlite' } }); await db.schema.createTable('messages', table => { table.increments('id'); table.string('text'); }); app.use('/messages', service({ Model: db, name: 'messages' })); app.listen(3030).then(() => console.log('Feathers server started on port 3030'));
Debug
Known issues
breakingVersion 8.0.0 dropped support for Node < 12 and changed the export to ESM-only.
fix
Use Node >= 12 and switch to ES module imports or use dynamic import for CJS projects.
affects: >=8.0.0
deprecatedThe `adapter.createQuery` method is deprecated; use `service.find` with query instead.
fix
Refactor code to use `service.find({ query: { ... } })` directly.
affects: >=7.0.0
gotchaIf `multi: true` is not set, `create` with an array will fail silently or throw an error.
fix
Set `multi: true` in the service options to allow batch creation.
affects: >=6.0.0
gotchaUsing `$search` in queries requires the `whitelist` option to include `$search`.
fix
Add `'$search'` to the `whitelist` array in service options.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: knex is not a function
Knex package is not a constructor when imported incorrectly in ESM.
fix
Use `import knex from 'knex';` (default import) instead of `import { knex } from 'knex';`.
Error: Cannot find module 'knex'
Knex is not installed as a dependency.
fix
Run `npm install knex` in your project.
Error: insert into `messages` (`text`) values (?) - SQLITE_ERROR: no such table: messages
The database table does not exist; schema not created.
fix
Create the table using `db.schema.createTable('messages', ...)` before using the service.
TypeError: service is not a function
Using the wrong import style; default export is a function, not an object.
fix
Use `import service from 'feathers-knex';` or `const service = require('feathers-knex');`.
Upgrade
Version history
8.0.1latest on npm
Audit
Dependencies
knexrequiredRequired peer dependency; the knex instance is passed as the Model option.
mysqloptionalDatabase driver for MySQL; install only if using MySQL.
pgoptionalDatabase driver for PostgreSQL; install only if using PostgreSQL.
sqlite3optionalDatabase driver for SQLite; install only if using SQLite.
Agent activity
7 hits · last 30 days
node
6
Resources
feathers-knex — npm install feathers-knex · libregistry