Skip to main content

MySQL adapter for @stash-it.

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
70%
Published
a day ago (0.1.0)

@stash-it/mysql-adapter

logo-stash-it-color-dark 2x

@stash-it/mysql-adapter is a simple redis adapter that can be used with @stash-it/stash-it. It uses mysql2 package under the hood.

Installation

npm

npm install @stash-it/mysql-adapter

deno

deno add @stash-it/mysql-adapter

yarn

yarn dlx jsr add @stash-it/mysql-adapter

pnpm

pnpm dlx jsr add @stash-it/mysql-adapter

bun

bunx jsr add @stash-it/mysql-adapter

Usage

// Import stash-it main class.
import { StashIt } from "@stash-it/stash-it";
import { MySqlAdapter } from "@stash-it/mysql-adapter";

// Create an instance of the adapter. Use whatever configuration your MySQL instance runs on.
const adapter = new MySqlAdapter({
  connection: {
    host: "localhost",
    user: "root",
    password: "password",
    database: "database-name",
    port: 3306, // optional property, if not set, this value is used
  },
  // The whole "table" configuration is optional
  // So are the properties of this object.
  // If not provided, those values are used and expected.
  table: {
    tableName: "items",
    keyColumnName: "key",
    valueColumnName: "value",
    extraColumnName: "extra",
  },
});

// And use it with stash-it.
const stash = new StashIt(adapter);

Table schema

If you don't have a table ready, you can use this query to create one. This is the expected schema.

CREATE TABLE `items` (
  `key` VARCHAR(255) PRIMARY KEY,
  `value` JSON NOT NULL,
  `extra` JSON NOT NULL
)

Development/testing

Running tests locally

Make sure to have .env file with those variables (and your values):

MYSQL_CONTAINER_NAME=mysql_container
MYSQL_DATABASE=database_name
MYSQL_USER=root
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_PORT=3306

And then execute pnpm test.

The tests you will run do all sorts of checks to verify if the adapter is capable of conducting CRUD operations.

If you want, you can target different DBs in different environments and run the tests against them. The test suite will clean up after self (or at least attempt), as it is designed to add numerous data, check if it is readable, and eventually it's removed.

License

MIT

Contribution

Feel free to open an issue or a pull request.

Add Package

deno add jsr:@stash-it/mysql-adapter

Import symbol

import * as mysql_adapter from "@stash-it/mysql-adapter";

---- OR ----

Import directly with a jsr specifier

import * as mysql_adapter from "jsr:@stash-it/mysql-adapter";

Add Package

npx jsr add @stash-it/mysql-adapter

Import symbol

import * as mysql_adapter from "@stash-it/mysql-adapter";

Add Package

yarn dlx jsr add @stash-it/mysql-adapter

Import symbol

import * as mysql_adapter from "@stash-it/mysql-adapter";

Add Package

pnpm dlx jsr add @stash-it/mysql-adapter

Import symbol

import * as mysql_adapter from "@stash-it/mysql-adapter";

Add Package

bunx jsr add @stash-it/mysql-adapter

Import symbol

import * as mysql_adapter from "@stash-it/mysql-adapter";