1.1.2 • Published 7 months ago

planetlocal v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Local HTTP interface for PlanetScale's Javascript Serverless Driver

A minimal HTTP server that allows you to use PlanetScale Javascript Driver to connect to a local instance of MySQL.

Useful for rapid development while saving those precious reads and writes. Supports transaction.

Usage

In a terminal window separate from your application, run:

npx planetlocal@latest --user <username> --password <password> --database <database>

Replace <username> and <password> with your MySQL credentials, and <database> with the name of the database you want to connect.

The default port is 4545, but you can specify a different one using the --port command:

--port 3030

Connecting to the local server

When instantiating @planetscale/database in your app, provide a custom fetch() to PlanetScale's config and use http://localhost:4545 as the url. Note: host, username and password fields can be omitted.

import { connect } from '@planetscale/database';

// Establish connection
const conn = connect({
  fetch: (url, init) => {
    return fetch('http://localhost:4545', init);
  }	
});

// Run query
const queryResult = await conn.execute('SELECT * FROM users');

// Run transaction
const transactionResult = await conn.transaction(async (tx) => {
  const a = await tx.execute('INSERT INTO users (name) VALUES (:name)', {name: 'Alice'});

  const b = await tx.execute('INSERT INTO users (name) VALUES (:name)', {name: 'Ben'});

  return [a, b];
})

Changelog

1.1.2 (10/13/23)

  • Fixed JSON column value not properly stringified.

1.1.1 (7/14/23)

  • Fixed 'Invalid character' when converting query results with btoa.

License

MIT

1.1.2

7 months ago

1.1.1

10 months ago

1.1.0

12 months ago

1.0.0

1 year ago

0.1.0

1 year ago

0.0.0-5

1 year ago