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

@dwn-protocol/dwn-sql-store

v0.0.6

Published

SQL data connectors for MessageStore, DataStore, and EventLog

Downloads

6

Readme

ID++ DWN SQL Stores

SQL backed implementations of DWN MessageStore, DataStore, and EventLog.

Supported DBs

  • SQLite ✔️
  • MySQL ✔️
  • PostgreSQL ✔️

Installation

npm install @dwn-protocol/dwn-sql-store

Usage

SQLite

import Database from 'better-sqlite3';

import { Dwn } from '@dwn-protocol/dwn-sdk-js'
import { SqliteDialect, MessageStoreSql, DataStoreSql, EventLogSql } from '@dwn-protocol/dwn-sql-store';

const sqliteDialect = new SqliteDialect({
  database: async () => new Database('dwn.sqlite', {
    fileMustExist: true,
  })
});

const messageStore = new MessageStoreSql(sqliteDialect);
const dataStore = new DataStoreSql(sqliteDialect);
const eventLog = new EventLogSql(sqliteDialect);

const dwn = await Dwn.create({ messageStore, dataStore, eventLog });

MySQL

import { createPool } from 'mysql2';
import { Dwn } from '@dwn-protocol/dwn-sdk-js'
import { MysqlDialect, MessageStoreSql, DataStoreSql, EventLogSql } from '@dwn-protocol/dwn-sql-store';

const mysqlDialect = new MysqlDialect({
  pool: async () => createPool({
    host     : 'localhost',
    port     : 3306,
    database : 'dwn',
    user     : 'root',
    password : 'dwn'
  })
});

const messageStore = new MessageStoreSql(mysqlDialect);
const dataStore = new DataStoreSql(mysqlDialect);
const eventLog = new EventLogSql(mysqlDialect);

const dwn = await Dwn.create({ messageStore, dataStore, eventLog });

PostgreSQL

import pg from 'pg';
import Cursor from 'pg-cursor';

import { Dwn } from '@dwn-protocol/dwn-sdk-js'
import { PostgresDialect, MessageStoreSql, DataStoreSql, EventLogSql } from '@dwn-protocol/dwn-sql-store';

const postgresDialect = new PostgresDialect({
  pool: async () => new pg.Pool({
    host     : 'localhost',
    port     : 5432,
    database : 'dwn',
    user     : 'root',
    password : 'dwn'
  }),
  cursor: Cursor
});

const messageStore = new MessageStoreSql(postgresDialect);
const dataStore = new DataStoreSql(postgresDialect);
const eventLog = new EventLogSql(postgresDialect);

const dwn = await Dwn.create({ messageStore, dataStore, eventLog });

Development

Prerequisites

node and npm

This project is using node v20.3.0 and npm v9.6.7. You can verify your node and npm installation via the terminal:

$ node --version
v18.13.0
$ npm --version
9.7.2

If you don't have node installed. Feel free to choose whichever approach you feel the most comfortable with. If you don't have a preferred installation method, i'd recommend using nvm (aka node version manager). nvm allows you to install and use different versions of node. It can be installed by running brew install nvm (assuming that you have homebrew)

Once you have installed nvm, install the desired node version with nvm install vX.Y.Z.

Docker

Docker is used to spin up a local containerized DBs for testing purposes. Docker from here

Running Tests

💡 Make sure you have all the prerequisites

  1. clone the repo and cd into the project directory
  2. Install all project dependencies by running npm install
  3. start the test databases using ./scripts/start-databases (requires Docker)
  4. run tests using npm run test

npm scripts

| Script | Description | | ----------------------- | ------------------------------------------- | | npm run build:esm | compiles typescript into ESM JS | | npm run build:cjs | compiles typescript into CommonJS | | npm run build | compiles typescript into ESM JS & CommonJS | | npm run clean | deletes compiled JS | | npm run test | runs tests. | | npm run test-coverage | runs tests and includes coverage | | npm run lint | runs linter | | npm run lint:fix | runs linter and fixes auto-fixable problems |