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

larvitorder-pg

v0.1.3

Published

Order library running on PostgreSQL

Downloads

7

Readme

Larvit order library running on PostgreSQL

Generic order module for nodejs.

order data structure:

{
	"uuid": ["string"],
	"fields": {
		"field1": [
			"value1",
			"value2"
		],
		"field2": [
			"value3"
		]
	},
	"rows": [
		{
			"uuid": ["string"],
			"field1": ["394"],
			"field2": ["nisse", "20"]
		}
	]
}

Installation

npm i larvitorder-pg

Usage

Initialize and requirements

First you need to set up a db connection. Larvitdb-pg is used here, but any compatible library will suffice.

import { Db } from 'larvitdb-pg';
import { Order } from 'larvitorder-pg';

const db = new Db(...); // Se documentation on https://github.com/larvit/larvitdb-pg
const order = new Order({ db });

Save an new order

Both create and update an existing order with the same call.

To create a new order, supply a non existing uuid or omit it completley, then a new will be generated.

const order = {
	uuid: ['03250c8c-bf88-44d8-a326-b6987d3990d1'],
	fields: {
		firstname: ['Günter'],
		lastname: ['Edelweiss', 'Schloffs'],
	},
	rows: [
		{
			price: ['399'],
			name: ['Screw'],
		},
		{
			price: ['34'],
			name: ['teh_foo'],
			tags: ['foo', 'bar'],
		},
	],
};

order.save(order).then(result => {
	console.log('order saved with uuid: ' + result.uuid);
}).catch(err => {
	throw err;
});

Remove orders from database

order.rm(['03250c8c-bf88-44d8-a326-b6987d3990d1']).then(() => {
	console.log('Orders are gone');
}).catch(err => {
	throw err;
});

Load order from database

order.get({
	uuids: ['03250c8c-bf88-44d8-a326-b6987d3990d1'], // Only return orders with these uuids
	matchAllFields: {firstname: 'Abraham', lastname: 'Lincoln'}, // Only return orders that have both the fields firstname and lastname that matches
	matchAllRowFields: {productName: 'A4 paper'}, // Only return orders that have rows matching both the row fieldname "productName" and the value "A4 paper"
	returnFields: ['firstname', 'lastname', 'status'], // Only return the order fields listed. IMPORTANT! Will return no order fields if not supplied! Because performance.
	returnRowFields: ['productName', 'price'], // Only return the order row fields listed. IMPORTANT! Will return no order row fields if not supplied! Because performance.
	limit: 100,
	offset: 100,
}).then(orders => {
	array of order objects
}).catch(err => {
	throw err;
});