Giter Club home page Giter Club logo

planetscale-node's Introduction

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.
  • 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

⚠️ 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:

~> 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.

export PLANETSCALE_TOKEN='[REDACTED]'
export PLANETSCALE_TOKEN_NAME='nyprhd2z6bd3'
export PLANETSCALE_ORG='[YOUR ORG]'
export PLANETSCALE_DB='[YOUR DB NAME]'
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

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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.