Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
A query builder for Postgres, MySQL and SQLite3, designed to be flexible, portable, and fun to use.
Knex.js is a SQL query builder for JavaScript, which works with multiple database systems like PostgreSQL, MySQL, SQLite3, and Oracle. It allows for building and executing SQL queries in a readable and programmatic way, handling connections and transactions, and seeding and migrating databases for development purposes.
Query Building
Builds a SQL query to select all columns from the 'users' table where the 'id' is 1.
knex.select('*').from('users').where('id', 1)
Schema Building
Creates a new table called 'users' with an auto-incrementing 'id' column, a 'name' column of string type, and timestamp columns for 'created_at' and 'updated_at'.
knex.schema.createTable('users', function(table) { table.increments('id'); table.string('name'); table.timestamps(); })
Transaction Support
Performs a transaction to insert multiple records into the 'books' table. If any part of the transaction fails, all changes are rolled back.
knex.transaction(function(trx) { const books = [{title: 'Canterbury Tales'}, {title: 'Macbeth'}]; return trx.insert(books).into('books'); })
Raw Queries
Executes a raw SQL query, selecting all columns from the 'users' table where the 'id' is 1, with parameter binding.
knex.raw('SELECT * FROM users WHERE id = ?', [1])
Seeding
Defines a seed file that first clears the 'users' table and then inserts new records into it.
exports.seed = function(knex) { return knex('users').del().then(function() { return knex('users').insert([{name: 'Alice'}, {name: 'Bob'}]); }); }
Migrations
Defines a migration file with an 'up' method to create a new 'users' table and a 'down' method to drop the 'users' table.
exports.up = function(knex) { return knex.schema.createTable('users', function(table) { table.increments(); table.string('name'); table.timestamps(); }); }; exports.down = function(knex) { return knex.schema.dropTable('users'); };
Sequelize is an ORM (Object-Relational Mapping) library for Node.js. It provides a higher-level abstraction for database interactions and supports multiple dialects. Unlike Knex, which is primarily a query builder, Sequelize allows for defining models and relationships directly in JavaScript.
TypeORM is an ORM for TypeScript and JavaScript (ES7, ES6, ES5). It supports the Data Mapper and Active Record patterns and works with SQL databases. It provides more advanced ORM features compared to Knex, such as automatic migration generation and support for decorators.
Bookshelf.js is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features a simple and intuitive API and supports relations, eager and lazy loading, model events, and plugins. It's more ORM-focused than Knex but uses Knex under the hood for query building.
._____. ______
| | / /
| | / /
| | _____ ._____ ._____. ,_____________. ______ / /
| | / / | \ | | / \ \ \ / /
| | / / | \ | | / \ \ \ / /
| | / / | \ | | / ,______. \ \ \ / /
| | / / | \ | | / / \ \ \ \/ /
| |/ \ | \ | | | | ____\ | \ /
| |\ \ | \| | | | / | \ \
| | \ \ | |\ | | | /__________| / \
| | \ \ | | \ | \ \ / /\ \
| | \ \ | | \ | \ \__________/\ / / \ \
| | \ \ | | \ | \ \ / / \ \
|_____| \_____\ |_____| \______| \_______________/ /_____/ \_____\
Knex.js is a multi-dialect query builder for Node.js.
For Docs, License, Tests, FAQ, and other information, see: http://knexjs.org
For a full ORM, see: http://bookshelfjs.org
To suggest a feature, report a bug, or general discussion: http://github.com/tgriesser/knex/issues/
0.4.10 - Oct 14, 2013
into
as an alias of from, for builder syntax of: insert(value).into(tableName)
FAQs
A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3
The npm package knex receives a total of 1,399,866 weekly downloads. As such, knex popularity was classified as popular.
We found that knex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.