Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/planetscale/planetscale-node
PlanetScale SQL Proxy NPM Module
https://github.com/planetscale/planetscale-node
Last synced: 3 months ago
JSON representation
PlanetScale SQL Proxy NPM Module
- Host: GitHub
- URL: https://github.com/planetscale/planetscale-node
- Owner: planetscale
- License: apache-2.0
- Archived: true
- Created: 2021-01-29T16:47:15.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-12T17:47:10.000Z (8 months ago)
- Last Synced: 2024-06-04T00:40:17.084Z (5 months ago)
- Language: TypeScript
- Size: 12.6 MB
- Stars: 56
- Watchers: 28
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# planetscale-node
⚠️ Do not use this package. It is from PlanetScale's early beta and no longer necessary. ⚠️
- To use PlanetScale with a Node.js application, follow our [Node.js guide](https://planetscale.com/docs/tutorials/connect-nodejs-app).
- PlanetScale is MySQL compatible and you can expect it to work with any MySQL node compatible library.
- For applications that require edge (http) connectivity, we recommend [database.js](https://github.com/planetscale/database-js)⚠️ The rest of the readme is for archival purposes only. ⚠️
## Installation
```
$ npm install planetscale-node
```## Setup
This code uses the PlanetScale API to provision a TLS certificate, and then connects to the database. It uses Service Tokens for authentication, so you'll need to create one for the app:
```bash
~> pscale service-token create
NAME TOKEN
-------------- ------------------------------------------
nyprhd2z6bd3 [REDACTED]~> pscale service-token add-access nyprhd2z6bd3 connect_production_branch --database [YOUR DB]
DATABASE ACCESSES
---------- ---------------------------
[YOUR DB] connect_production_branch
```## Usage
Set the following environment variables in your application.
```bash
export PLANETSCALE_TOKEN='[REDACTED]'
export PLANETSCALE_TOKEN_NAME='nyprhd2z6bd3'
export PLANETSCALE_ORG='[YOUR ORG]'
export PLANETSCALE_DB='[YOUR DB NAME]'
``````javascript
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()
```### Using prepared statements
```javascript
const { PSDB } = require('planetscale-node')
const conn = new PSDB('main')async function main() {
const [rows, fields] = await conn.execute('select * from reminders where id > ?', [10])
console.log(rows, fields)
}main()
```