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

hq-pg

v1.1.1

Published

Lightweight modeling and express routes example for PostgreSQL data

Downloads

15

Readme

hq-pg

Installation

npm install hq-pg --save

Getting Started

//initialize the module with your knex instance
var HQ = require('hq-pg')(knex)

//start defining your models
var Items = new HQ.Model('items')

var Locations = new HQ.Model('locations')

var Users = new HQ.UserModel('users')

var Devices = new HQ.DeviceModel('devices', {
	expiryCount: 1,
	expiryUnits: 'day'
})

var ItemsLocations = new HQ.Model('items_locations', {
	filterKnex(knex) {
		return knex
			.join('items', 'items_locations.item_id', '=', 'items.id')
			.join('locations', 'items_locations.location_id', '=', 'locations.id')
	}
})

//see them in action
Users.create({ email: '[email protected]', password: 'test' }, '*', console.log)

require('hq-pg')(knex)

Returns three classes: Model, UserModel, and DeviceModel:

HQ.Model Methods

All of these methods can be extended or redefined through normal model inheritance.

create(data, returning, onDone(err, data, status, message) )

batchCreate(data, onDone(err, data) )
/ /where on conflict, the row attempted to be inserted does nothing

select(returning, onDone(err, data, status) )

findAll(where, returning, onDone(err, data, status) )

find(where, returning, onDone(err, data, status) )

findById(id, returning, onDone(err, data, status) )

findOrCreate(data, returning, onDone(err, data, status, message) )

updateAll(where, data, returning, onDone(err, data, status, message) )

update(where, data, returning, onDone(err, data, status, message) )

destroy(where, onDone(err, data, status) )

HQ.UserModel Methods

All of these methods can be extended or redefined through normal model inheritance. (These all are in addition to those available in the Model class.)

generatePassword(password)

passwordMatches(password, hash)

safe(data)

validateLoginAndFind(email, password, onDone(err, data, status) )

HQ.DeviceModel Methods

All of these methods can be extended or redefined through normal model inheritance. (These all are in addition to those available in the Model class.)

generateToken()

timeFormatted(m)

dataForCreate(req, user_id)

getTokenFromReq(req, header) 

findByActiveToken(token, returning, onDone(err, data, status) )

expireAllByUserId(user_id, returning, onDone(err, data, status, message) )

Example

Comes with a fully fleshed out example, so you can see this in action and start implementing in your project.

Getting Started with the Example

  1. Clone this repo and start there;
  2. npm install knex -g, if you don't have Knex CLI already installed;
  3. npm install if you haven't already;
  4. Create your .env file in the example folder of this repo. Make sure it contains the variables specified in example.env
  5. npm run example:migrate:latest to ensure our table schemas;
  6. npm run example

For cURL samples using the example application, look to the README in the example folder.