planetscale / planetscale-node Goto Github PK
View Code? Open in Web Editor NEWPlanetScale SQL Proxy NPM Module
License: Apache License 2.0
PlanetScale SQL Proxy NPM Module
License: Apache License 2.0
I've been evaluating PlanetScale for use with serverless applications (specifically NextJS). I love the CLI and database offering, but I've found that planetscale-node
at its current state is unusable for serverless applications.
In the serverless paradigm, each request to a cloud function will create a new connection to the database. With planetscale-node
, creating a connection and executing the first query consistently takes more than three seconds, sometimes even four (!). (Subsequent queries take ~150ms).
I did some digging and found that the great majority (~96%) of that time is spent waiting for a POST request to create a TLS certificate, prior to starting the database connection itself (see postJSON
).
Is it expected for certificate creation to take that long?
Are there any plans to support serverless applications?
Hi, today I was working with Planetscale and planetscale-node
package. I followed all the steps in docs. When I run a basic query example on Node.js, I get a forbidden response with a 403
status code.
It happens in certificate request in postJSON function. I debugged the code and got all the header
, body
data from the debugger, tried to send post request on Postman with same informations and I got 200.
After a few hours, wanted to try axios
for this request and it was successful again. Cannot sure the http.request
implementation is wrong somehow or it is just me.
What do you think?
const { PSDB } = require('./dist/index.js')
const conn = new PSDB('main')
async function main() {
const [rows, fields] = await conn.execute('select * from likes')
console.log(rows, fields)
}
main()
undefined:1
<html>
^
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (REPO_PATH/planetscale-node/dist/index.js:102:69)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
What's the plan with this library in regards to using it with other libraries like Knex? Can I just use the connection object? Or is the plan to only be able to use this library?
In my app I use the execute
method to create prepared statements. I would like to be able to do the same using the planetscale-node client.
https://www.npmjs.com/package/mysql2#using-prepared-statements
Additionally I would like to see the end
method exposed.
I imagine any other public methods of the underlying mysql client will also need to be exposed sometime in the future.
If you try to connect and your service token is missing the connect_branch
or connect_production_branch
access you simply get a generic Http 404
error in the response. Not helpful. It would be nice to have more descriptive errors for things like this.
Apologies if this is the wrong place for feedback. I know it's more of a planetscale API issue rather than the planetscale-node client.
While seeding a database using a node script I'll occasionally get the following error:
C:\projects\...\node_modules\mysql2\promise.js:110
const localErr = new Error();
^
Error: 23264:error:140943FC:SSL routines:ssl3_read_bytes:sslv3 alert bad record mac:c:\ws\deps\openssl\openssl\ssl\record\rec_layer_s3.c:1544:SSL alert number 20
at PromiseConnection.execute (C:\projects\...\node_modules\mysql2\promise.js:110:22)
at PSDB.execute (C:\projects\...\node_modules\planetscale-node\dist\index.js:29:43)
at Object.module.exports.seed (C:\projects\...\seed.js:25:18)
at processTicksAndRejections (node:internal/process/task_queues:94:5) {
code: 'ERR_SSL_SSLV3_ALERT_BAD_RECORD_MAC',
errno: undefined,
sqlState: undefined,
sqlMessage: undefined
}
I can't reliably reproduce it but it happens often enough to deserve its own issue.
Hi,
Can't wait to get stuck into this, does this work with aws lambda yet?
Bests,
Sean.
Running the basic example in the README.md crashes with:
PS C:\projects\planetscale-node-test> node .\test.js
C:\projects\planetscale-node-test\node_modules\planetscale-node\dist\index.js:38
throw new Error(`HTTP ${status}`);
^
Error: HTTP 404
at PSDB.createConnection (C:\projects\planetscale-node-test\node_modules\planetscale-node\dist\index.js:38:19)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async PSDB.query (C:\projects\planetscale-node-test\node_modules\planetscale-node\dist\index.js:21:32)
at async main (C:\projects\planetscale-node-test\test.js:5:28)
Code, for reference:
const { PSDB } = require('planetscale-node')
const conn = new PSDB('main')
async function main() {
const [rows, fields] = await conn.query('select * from reminders')
console.log(rows, fields)
}
main()
I can't find a clear way to run my queries on PlanetScale other than going through this library or should I use this library as a connection intermediary to power my existing ORM nodeJS (sequelize) without having to do the initial handshake with the CLI pscale connect <my-db> main --execute '<my-app-main>'
?
Is there a reference for the correct way to do this?
I just connected PlanetScale with Prisma and Vercel and there was a bit more friction than I think was necessary. I started with the Vercel integration, which added some env variables. It wasn't clear how I was expected to connect, but I ended up doing it initially with a single DB_URL env variable, and ultimately made a URL builder function.
It seems like this setup should be easier. I'm not sure exactly the best way, but perhaps one way could be by exposing a simple URL builder function in this package.
My implementation is as follows:
const dbUrl = () => {
const user = process.env.PLANETSCALE_DB_USERNAME;
const password = process.env.PLANETSCALE_DB_PASSWORD;
const db = process.env.PLANETSCALE_DB;
const host = process.env.PLANETSCALE_DB_HOST;
const certPath = process.env.PLANETSCALE_SSL_CERT_PATH;
const hasAllValues =
[user, password, db, host, certPath].findIndex(value => !value) === -1;
if (!hasAllValues) return null;
return `mysql://${user}:${password}@${host}/${db}?sslmode=require&sslcert=${certPath}`;
};
Seeing the same time reflected differently when I retrieve it from pscale CLI compared with the planetscale-node:
From planetscale-node: "created_ts":"2021-09-29T12:53:37.000Z","updated_ts":"2021-09-29T12:57:39.000Z
From pscale CLI: 2021-09-29 05:53:37 | 2021-09-29 05:57:39
The UTC time is actually 2021-09-29 05:57:39
, so the UTC timestamp coming from planetscale-node is pretty confusing.
I suspect this is due to sidorares/node-mysql2#1337 .
Can anyone help me to upload and download files on planet scale using node js.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.