Knex.js logo

Knex.js

SQL query builder for Postgres, MySQL, MariaDB, SQLite3, and Oracle
116
217
+ 1
32

What is Knex.js?

Knex.js is a "batteries included" SQL query builder for Postgres, MySQL, MariaDB, SQLite3, and Oracle designed to be flexible, portable, and fun to use. It features both traditional node style callbacks as well as a promise interface for cleaner async flow control, a stream interface, full featured query and schema builders, transaction support (with savepoints), connection pooling and standardized responses between different query clients and dialects.
Knex.js is a tool in the Database Tools category of a tech stack.
Knex.js is an open source tool with 12.7K GitHub stars and 1.5K GitHub forks. Here’s a link to Knex.js's open source repository on GitHub

Who uses Knex.js?

Companies
25 companies reportedly use Knex.js in their tech stacks, including 꿀리뷰, Decision6, and Backend.

Developers
86 developers on StackShare have stated that they use Knex.js.

Knex.js Integrations

MySQL, PostgreSQL, SQLite, Oracle, and Trails are some of the popular tools that integrate with Knex.js. Here's a list of all 8 tools that integrate with Knex.js.
Public Decisions about Knex.js

Here are some stack decisions, common use cases and reviews by companies and developers who chose Knex.js in their tech stack.

Tim Nolet
Tim Nolet
Founder, Engineer & Dishwasher at Checkly · | 20 upvotes · 1.4M views

Heroku Docker GitHub Node.js hapi Vue.js AWS Lambda Amazon S3 PostgreSQL Knex.js Checkly is a fairly young company and we're still working hard to find the correct mix of product features, price and audience.

We are focussed on tech B2B, but I always wanted to serve solo developers too. So I decided to make a $7 plan.

Why $7? Simply put, it seems to be a sweet spot for tech companies: Heroku, Docker, Github, Appoptics (Librato) all offer $7 plans. They must have done a ton of research into this, so why not piggy back that and try it out.

Enough biz talk, onto tech. The challenges were:

  • Slice of a portion of the functionality so a $7 plan is still profitable. We call this the "plan limits"
  • Update API and back end services to handle and enforce plan limits.
  • Update the UI to kindly state plan limits are in effect on some part of the UI.
  • Update the pricing page to reflect all changes.
  • Keep the actual processing backend, storage and API's as untouched as possible.

In essence, we went from strictly volume based pricing to value based pricing. Here come the technical steps & decisions we made to get there.

  1. We updated our PostgreSQL schema so plans now have an array of "features". These are string constants that represent feature toggles.
  2. The Vue.js frontend reads these from the vuex store on login.
  3. Based on these values, the UI has simple v-if statements to either just show the feature or show a friendly "please upgrade" button.
  4. The hapi API has a hook on each relevant API endpoint that checks whether a user's plan has the feature enabled, or not.

Side note: We offer 10 SMS messages per month on the developer plan. However, we were not actually counting how many people were sending. We had to update our alerting daemon (that runs on Heroku and triggers SMS messages via AWS SNS) to actually bump a counter.

What we build is basically feature-toggling based on plan features. It is very extensible for future additions. Our scheduling and storage backend that actually runs users' monitoring requests (AWS Lambda) and stores the results (S3 and Postgres) has no knowledge of all of this and remained unchanged.

Hope this helps anyone building out their SaaS and is in a similar situation.

See more
Tim Nolet
Tim Nolet
Founder, Engineer & Dishwasher at Checkly · | 10 upvotes · 116.7K views

PostgreSQL Heroku Heroku Postgres Node.js Knex.js

Last week we rolled out a simple patch that decimated the response time of a Postgres query crucial to Checkly. It quite literally went from an average of ~100ms with peaks to 1 second to a steady 1ms to 10ms.

However, that patch was just the last step of a longer journey:

  1. I looked at what API endpoints were using which queries and how their response time grew over time. Specifically the customer facing API endpoints that are directly responsible for rendering the first dashboard page of the product are crucial.

  2. I looked at the Heroku metrics such as those reported by heroku pg:outlier and cross references that with "slowest response time" statistics.

  3. I reproduced the production situation as best as possible on a local development machine and test my hypothesis that an composite index on a uuid field and a timestampz field would reduce response times.

This method secured the victory and we rolled out a new index last week. Response times plummeted. Read the full story in the blog post.

See more
Shared insights
on
Knex.jsKnex.js
at

Not an ORM but a query builder. So developers are encouraged or sometimes forced to think about SQL and database layer, which is a good thing. Knex.js

See more

Knex.js's Features

  • SQL query builder for Postgres, MySQL, MariaDB, SQLite3, and Oracle

Knex.js Alternatives & Comparisons

What are some alternatives to Knex.js?
Knex.js
Knex.js is a "batteries included" SQL query builder for Postgres, MySQL, MariaDB, SQLite3, and Oracle designed to be flexible, portable, and fun to use. It features both traditional node style callbacks as well as a promise interface for cleaner async flow control, a stream interface, full featured query and schema builders, transaction support (with savepoints), connection pooling and standardized responses between different query clients and dialects.
Sequelize
Sequelize is a promise-based ORM for Node.js and io.js. It supports the dialects PostgreSQL, MySQL, MariaDB, SQLite and MSSQL and features solid transaction support, relations, read replication and more.
Slick
It is a modern database query and access library for Scala. It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred.
Sequel Pro
Sequel Pro is a fast, easy-to-use Mac database management application for working with MySQL databases.
Spring Data
It makes it easy to use data access technologies, relational and non-relational databases, map-reduce frameworks, and cloud-based data services. This is an umbrella project which contains many subprojects that are specific to a given database.
See all alternatives

Knex.js's Followers
217 developers follow Knex.js to keep up with related blogs and decisions.
Yurij Borsch
Phani Gopaluni
Matheus Andre
Lucas Fontes Gaspareto
Rahul Patel
Amal Mulia
peyo
Marty Johnson
Emile John Garcia
edisplay