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

lockit-sql-adapter

v0.5.3

Published

SQL adapter for lockit. Works with PostgreSQL, MySQL, SQLite and MariaDB

Downloads

26

Readme

Lockit SQL adapter

Build Status NPM version

SQL adapter for Lockit.

Installation

npm install lockit-sql-adapter

var adapter = require('lockit-sql-adapter');

The adapter is built on top of sequelize. The following databases are supported:

  • MySQL
  • MariaDB (not yet tested but should work)
  • SQLite
  • PostgreSQL

You have to install the connector for your database of choice manually.

npm install pg       # for postgres
npm install mysql    # for mysql
npm install sqlite3  # for sqlite
npm install mariasql # for mariasql

Configuration

The following settings are required.

// for postgres
exports.db = {
  url: 'postgres://127.0.0.1:5432/',
  name: 'users',
  collection: 'my_user_table'  // table name
};

// for mysql
// exports.db = {
//   url: 'mysql://127.0.0.1:3306/',
//   name: 'users',
//   collection: 'my_user_table'  // table name
// };

// for sqlite
// exports.db = {
//   url: 'sqlite://',
//   name: ':memory:',
//   collection: 'my_user_table'  // table name
// };

Features

1. Create user

adapter.save(name, email, pass, callback)

  • name: String - i.e. 'john'
  • email: String - i.e. '[email protected]'
  • pass: String - i.e. 'password123'
  • callback: Function - callback(err, user) where user is the new user now in our database.

The user object has the following properties

  • _id: unique id
  • name: username chosen during sign up
  • email: email that was provided at the beginning
  • salt: salt generated by crypto.randomBytes()
  • derived_key: password hash generated by pbkdf2
  • signupTimestamp: Date object to remember when the user signed up
  • signupToken: unique token sent to user's email for email verification
  • signupTokenExpires: Date object usually 24h ahead of signupTimestamp
  • failedLoginAttempts: save failed login attempts during login process, default is 0
adapter.save('john', '[email protected]', 'secret', function(err, user) {
  if (err) console.log(err);
  console.log(user);
  // {
  //   _id: 1,
  //   name: 'john',
  //   email: '[email protected]',
  //   derived_key: 'c4c7a83f7b3936437798316d4c7b8c7b731a55dc',
  //   salt: 'ff449a4980a58a80c4ed80bddd34b8c9',
  //   signupToken: '13eefbe7-6bc8-43f5-b27f-0bf0ca98b8db',
  //   signupTimestamp: Fri Apr 11 2014 21:37:47 GMT+0200 (CEST),
  //   signupTokenExpires: Sat Apr 12 2014 21:37:47 GMT+0200 (CEST),
  //   failedLoginAttempts: 0,
  //   emailVerificationTimestamp: null,
  //   emailVerified: null,
  //   pwdResetToken: null,
  //   pwdResetTokenExpires: null,
  //   accountLocked: null,
  //   accountLockedUntil: null,
  //   previousLoginTime: null,
  //   previousLoginIp: null,
  //   currentLoginTime: null,
  //   currentLoginIp: null
  // }
});

2. Find user

adapter.find(match, query, callback)

  • match: String - one of the following: 'name', 'email' or 'signupToken'
  • query: String - corresponds to match, i.e. '[email protected]'
  • callback: Function - callback(err, user)
adapter.find('name', 'john', function(err, user) {
  if (err) console.log(err);
  console.log(user);
  // {
  //   _id: 1,
  //   name: 'john',
  //   email: '[email protected]',
  //   derived_key: '75b43d8393715cbf476ee55b12f888246d7f7015',
  //   salt: 'f39f9a5104e5ae61347dced750b63b16',
  //   signupToken: '6c93c6f8-06b6-4c6d-be58-1e89e8590d0f',
  //   signupTimestamp: Fri Apr 11 2014 21:39:28 GMT+0200 (CEST),
  //   signupTokenExpires: Sat Apr 12 2014 21:39:28 GMT+0200 (CEST),
  //   failedLoginAttempts: 0,
  //   emailVerificationTimestamp: null,
  //   emailVerified: null,
  //   pwdResetToken: null,
  //   pwdResetTokenExpires: null,
  //   accountLocked: null,
  //   accountLockedUntil: null,
  //   previousLoginTime: null,
  //   previousLoginIp: null,
  //   currentLoginTime: null,
  //   currentLoginIp: null
  // }
});

3. Update user

adapter.update(user, callback)

  • user: Object - must have _id key
  • callback: Function - callback(err, user) - user is the updated user object
// get a user from db first
adapter.find('name', 'john', function(err, user) {
  if (err) console.log(err);

  // add some new properties to our existing user
  user.firstOldKey = 'and some value';
  user.secondOldKey = true;

  // save updated user to db
  adapter.update(user, function(err, user) {
    if (err) console.log(err);
    // ...
  });
});

4. Delete user

adapter.remove(name, callback)

  • name: String
  • callback: Function - callback(err, res) - res is true if everything went fine
adapter.remove('john', function(err, res) {
  if (err) console.log(err);
  console.log(res);
  // true
});

Test

grunt

License

MIT