@polyscale/serverless-js
v1.4.0
Published
![npm (scoped)](https://img.shields.io/npm/v/@polyscale/serverless-js?color=%23b03348) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/polyscale/serverless-js/publish.yml) ![GitHub](https://img.shields.io/github/license/pol
Downloads
57
Readme
PolyScale Serverless Client
Serverless-js
is a lightweight, Fetch API based HTTP client designed for executing SQL over HTTP with PolyScale.ai. Serverless-js
is intended for use in serverless environments where TCP based database connections are unavailable e.g. Vercel and Cloudflare Workers.
Install
npm install @polyscale/serverless-js
Usage
TypeScript/ESM:
import {Client} from "@polyscale/serverless-js";
const polyscale = new Client("https://serverless.aws.psedge.global", {
cacheId: "polyscale-cache-id",
username: "target-db-username",
password: "target-db-password",
database: "target-db-database",
provider: "mysql",
});
polyscale.query("SELECT 1;").then(result => console.log(result))
Deno:
import {Client} from "npm:@polyscale/serverless-js";
const polyscale = new Client("https://serverless.aws.psedge.global", {
cacheId: "polyscale-cache-id",
username: "target-db-username",
password: "target-db-password",
database: "target-db-database",
provider: "mysql",
});
polyscale.query("SELECT 1;").then(result => console.log(result))
Commonjs:
const {Client} = require("@polyscale/serverless-js");
const polyscale = new Client("https://serverless.aws.psedge.global", {
cacheId: "polyscale-cache-id",
username: "target-db-username",
password: "target-db-password",
database: "target-db-database",
provider: "mysql",
});
polyscale.query("SELECT 1;").then(result => console.log(result))
Parameter Bindings
See knex documentation for more information.
import {Client} from "@polyscale/serverless-js";
const polyscale = new Client("https://serverless.aws.psedge.global", {
cacheId: "polyscale-cache-id",
username: "target-db-username",
password: "target-db-password",
database: "target-db-database",
provider: "mysql",
});
polyscale.query("SELECT * FROM user WHERE name = ?;", ["Peter"]).then(result => console.log(result))
polyscale.query("SELECT * FROM user WHERE name = :name;", {name: "Peter"}).then(result => console.log(result))