npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shopify/shopify-app-session-storage-drizzle

v2.0.8

Published

Shopify App Session Storage for Drizzle

Downloads

620

Readme

Session Storage Adapters for Drizzle

This package implements the SessionStorage interface that works with an instance of Drizzle.

There are 3 adapters for Drizzle: DrizzleSessionStoragePostgres, DrizzleSessionStorageSQLite and DrizzleSessionStorageMySQL.

Session storage for Drizzle requires a schema.ts with a session table with at-least the columns as in the example. Make sure to create session table and apply changes to the database before using this pakacge.

Example with PostgreSQL

import {bigint, boolean, pgTable, text, timestamp} from 'drizzle-orm/pg-core';

export const sessionTable = pgTable('session', {
  id: text('id').primaryKey(),
  shop: text('shop').notNull(),
  state: text('state').notNull(),
  isOnline: boolean('isOnline').default(false).notNull(),
  scope: text('scope'),
  expires: timestamp('expires', {mode: 'date'}),
  accessToken: text('accessToken'),
  userId: bigint('userId', {mode: 'number'}),
});

You can then instantiate and use DrizzleSessionStoragePostgres like so:

import {shopifyApp} from '@shopify/shopify-app-express';
import {DrizzleSessionStoragePostgres} from '@shopify/shopify-app-session-storage-drizzle';

import {db} from './db.server';
import {sessionTable} from './schema';

const storage = new DrizzleSessionStoragePostgres(db, sessionTable);

const shopify = shopifyApp({
  sessionStorage: storage,
  // ...
});

Example with MySQL

import {
  bigint,
  boolean,
  mysqlTable,
  text,
  timestamp,
  varchar,
} from 'drizzle-orm/mysql-core';

export const sessionTable = mysqlTable('session', {
  id: varchar('id', {length: 255}).primaryKey(),
  shop: text('shop').notNull(),
  state: text('state').notNull(),
  isOnline: boolean('isOnline').default(false).notNull(),
  scope: text('scope'),
  expires: timestamp('expires', {mode: 'date'}),
  accessToken: text('accessToken'),
  userId: bigint('userId', {mode: 'number'}),
});

You can then instantiate and use DrizzleSessionStorageMySQL like so:

import {shopifyApp} from '@shopify/shopify-app-express';
import {DrizzleSessionStorageMySQL} from '@shopify/shopify-app-session-storage-drizzle';

import {db} from './db.server';
import {sessionTable} from './schema';

const storage = new DrizzleSessionStorageMySQL(db, sessionTable);

const shopify = shopifyApp({
  sessionStorage: storage,
  // ...
});

Example with SQLite

import {sqliteTable, text, integer, blob} from 'drizzle-orm/sqlite-core';

export const sessionTable = sqliteTable('session', {
  id: text('id').primaryKey(),
  shop: text('shop').notNull(),
  state: text('state').notNull(),
  isOnline: integer('isOnline', {mode: 'boolean'}).notNull().default(false),
  scope: text('scope'),
  expires: text('expires'),
  accessToken: text('accessToken'),
  userId: blob('userId', {mode: 'bigint'}),
});

You can then instantiate and use DrizzleSessionStorageSQLite like so:

import {shopifyApp} from '@shopify/shopify-app-express';
import {DrizzleSessionStorageSQLite} from '@shopify/shopify-app-session-storage-drizzle';

import {db} from './db.server';
import {sessionTable} from './schema';

const storage = new DrizzleSessionStorageSQLite(db, sessionTable);

const shopify = shopifyApp({
  sessionStorage: storage,
  // ...
});

Drizzle Setup

In the example above the file db.server.ts should import your database client, drizzle schema and export db that you can pass to the storage adapter:

import {drizzle} from 'drizzle-orm/libsql';
import {createClient} from '@libsql/client';

import * as schema from './schema';

export const client = createClient({
  url: 'file:./dev.db',
});

export const db = drizzle(client, {schema});

Follow the Drizzle documentation for PostgreSQL setup, MySQL setup and SQLite setup.