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

storkSQL

v0.1.34

Published

A SQL ORM with Mongoose-like syntax. Built on top of knex.

Downloads

36

Readme

Getting Started

https://github.com/alexcstark/storkSQL

You'll need two things to get started: the library and a DB client.

npm install storkSQL

npm install pg

Stork uses knex which supports pg, mySQL, and SQlite.

Configure the database

db.js

import Stork from 'storkSQL';
// Put your information below
const DB_CONFIG_OBJ = {
  host: '',
  password: '',
  database: '',
  port: 3241,
  user: '',
  ssl: true
};
export default new Stork({
  connection: DB_CONFIG_OBJ,
  client:'pg'
});

The following methods on the db object exist to help you manage your database. See the bottom of the page for an example.

  dropTableIfExists(tableName)
  hasTable(tableName)
  createTable(tableName, schema)
  endConnection()

Set up your schema and models

User.js

import db from './path/to/db.js';
export const UserSchema = function (user) {
  user.increments('id').primary();
  user.string('email', 100).unique();
  user.string('password', 100);
  user.string('homeLatitude', 100);
  user.string('homeLongitude', 100);
  user.string('homeAddress', 100);
  user.timestamps();
};
export const User = db.model('users', UserSchema);

This will give you access to the following queries:

findAll()
findById(id)
find(obj)
findOne(obj)
findOrCreate(obj)
create(obj)
save(obj)
updateOrCreate(obj)
update(criteriaObj, updateObj)
remove(obj)

Each query will return a promise that must be resolved, like so:

User.find({id: req.params.userid})
  .then((user) => res.json(user));
};

The library also support salting, hashing, and comparing passwords for users or other secure data. Secure fields (as seen below) are salted and hashed by the ORM.

models/User.js

export const UserSchema = function (user) {
  user.increments('id').primary();
  user.timestamp('created_at').defaultTo(db.knex.fn.now());
  // carvis auth -- might be factored out.
  user.string('email', 255).unique();
  user.string('password', 100);
  user.text('alexaUserId', 'longtext').unique();
  // data returned from lyft specific functions
  user.string('firstName', 100);
  user.string('lastName', 100);
  user.string('lyftEmail', 100);
  // the phone number used for lyft authentication
  user.string('lyftPhoneNumber', 100);
  // data lyft uses for request-ride calls
  user.text('lyftPaymentInfo', 'longtext');
  user.text('lyftToken', 'longtext');
  user.text('uberToken', 'longtext');
  // data used for uber authentication
  user.string('uberEmail', 255);
  user.string('uberPassword', 255);
};

export const User = db.model('users', UserSchema, {
  secureFields: {
    password: process.env.USER_ENCRYPT,
    fields: ['lyftToken', 'lyftPaymentInfo', 'uberPassword', 'uberToken', 'password', 'alexaUserId']
  }
});

It is recommended to create files to help manage your DB like this:

import db from '../db';
import {RideSchema} from '../Ride';
import {UserSchema} from '../User';

const resetDb = async function() {
  await db.dropTableIfExists('users');
  console.log('dropping users table');
  await db.dropTableIfExists('rides');
  console.log('dropping rides table');

  if (!(await db.hasTable('users'))) {
    await db.createTable('users', UserSchema);
    console.log('created new users table');
  }

  if (!(await db.hasTable('rides'))) {
    await db.createTable('rides', RideSchema);
    console.log('created new rides table');
  }

  await db.endConnection(); /* eslint-ignore */
  console.log('connection destroyed');
};

resetDb();

Remember to transpile as async/await isn't supported everywhere, yet.

knex

All of the code is written on top of knex. Want access to a method that hasn't been written?

http://knexjs.org/

After you've set up your database connection, use db.knex for access to all of knex's functionality!

To-Do

  • Relationships and joins