Knex with Neon Serverless Driver
I am using Knex.js as my query builder. I want to use it alongside Neon's serverless driver. I'm using this repo as an example (https://github.com/neondatabase/neon-vercel-knex/tree/main)
However it is not working, I am getting the following error. Would really appreciate some help with
I'm on "knex": "^3.1.0" and "neonctl": "^1.29.3"
Could not find a declaration file for module 'knex/lib/dialects/postgres'. '/Users/xxxxx/Desktop/projects/goldengate/node_modules/knex/lib/dialects/postgres/index.js' implicitly has an 'any' type.
If the 'knex' package actually exposes this module, try adding a new declaration (.d.ts) file containing declare module 'knex/lib/dialects/postgres';ts(7016)
GitHub
GitHub - neondatabase/neon-vercel-knex: Example use of Neon serverl...
Example use of Neon serverless driver on Vercel Edge Functions with Knex.js - neondatabase/neon-vercel-knex
12 Replies
clever-tan•2y ago
I can test the repository shortly. Are you sure you ran
npm install in the root of the repository?
@leosmissingpaw it worked for me. I had to make one change for local development. Rename the env.local file to .env
like-goldOP•2y ago
@ShinyPokemon interesting, I'm trying to adapt my existing codebase with the example.
like-goldOP•2y ago


clever-tan•2y ago
Did you run
npm install pg and npm i knexlike-goldOP•2y ago
yes, this is in my package.json
like-goldOP•2y ago
@ShinyPokemon

clever-tan•2y ago
The Neon example uses 2.x of Knex
I assume that's the difference. There are probably breaking changes in 3x. We will need to update our sample
clever-tan•2y ago
GitHub
neon-vercel-knex/package.json at main · neondatabase/neon-vercel-knex
Example use of Neon serverless driver on Vercel Edge Functions with Knex.js - neondatabase/neon-vercel-knex
clever-tan•2y ago
I tested and the following works with 3.x. Create a Node.js project with a package.json, then run:
Create a file named
index.js and add this code:
Create a file named .env and add the DATABASE_URL for your Neon database.
Run the process using a command like:
node -r dotenv/config index.js
It will print the Postgres version.
I will need to investigate if 3.x supports custom drivers, i.e our servereless driverlike-goldOP•2y ago
yes please, an update would be appreciated. We have a service wired with knex and it's a non-starter for us to move off of it
Hi @ShinyPokemon any updates?
clever-tan•2y ago
Hey @leosmissingpaw, try this! Remember, this is a hacked together implementation I just created! https://gist.github.com/evanshortiss/23c679dbd13a2cb0d0198a9d8b79d211
Gist
Using knex@3.x with Neon's HTTP Driver
Using knex@3.x with Neon's HTTP Driver. GitHub Gist: instantly share code, notes, and snippets.
clever-tan•2y ago
I'll need to dive deeper into the
Knex.Client class to fully understand what functions need to be implemented etc. Maybe you can start with this and we can collab on making it more feature complete?