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

amk-sql

v1.0.0-rc5

Published

sql knex plugin for amk

Downloads

24

Readme

AMK-SQL

CircleCI codecov Known Vulnerabilities

AMK-SQL is a plugin for express using knex to simplify the usage of SQL databases

Setup

Set the following environment variables

  • AMK_SQL_USERNAME
  • AMK_SQL_PASSWORD
  • AMK_SQL_HOST
  • AMK_SQL_DATABASE
  • AMK_SQL_CLIENT
  • AMK_SQL_POOL_MIN (connection pool, default = 2)
  • AMK_SQL_POOL_MAX (connection pool, default = 10)

you can achieve this by choosing one of the options below:

  1. use dotenv to set the variables
  2. issue the command export AMK_SQL_USERNAME=username
  3. put it on the .bashrc or .bash_profile file

Usage

After setting up environment variables, inherit from this amk-sql. refer to code snipet below:

users.js

const SQL = require('amk-sql');

class Users extends SQL {
	constructor() {
		super('users', 'u')
	}
}
module.exports = Users;

using users.js

Users = require('./users');

const users = new Users();
// this will give you a list of 20 users that are active
const rs = await users.get({active: 1}, { limit=20, orderBy='email'})

For more advance usage, please refer to this

API

find(param1, param2, param3)


Simple query with filters

Arguments
  • param1 (string or object) - can be an object to filter
  • param2 (string) - can be ('param', 'value')
  • param3 (string) - can be ('param', 'in', 'value')
Returns
  • (Array|Promise) - result set in an array or query object

get(params, { limit, offset, groupBy, orderBy})


Querying dataset with pagination

Arguments
  • param (string) - query parameter
  • limit (number) - limit
  • offset (number) - offset (limit is required if offset is set)
  • groupBy (string) - group by statement
  • orderBy (string|Object) - order by or order by and direction
Returns
  • (Array|Promise) - result set in an array or query object

count(params, { groupBy })


Count the number of entry in a table

Arguments
  • param (string) - query parameter
  • groupBy (string) - group by statement
Returns
  • (Array|Promise) - count in an array or query object. suggest to use destructuring like let [count] = model.count() to get the value

ins(params, returning)


function to insert a single row of data

Arguments
  • params (object) - the row you are going to insert
  • returning (Array|Promise) - the row value you want returned i.e. primary keys or the query object
Returns
  • (Array) - returns the number of rows inserted or the return value specified on the arguments

upd(updateValue, params, returning)


function to update rows of data

Arguments
  • updateValue (object) - value you want to change
  • params (object) - the criteria of which row to update
  • returning (string) - the row value you want returned i.e. primary keys
Returns
  • (Array|Promise) - returns the number of rows inserted or the return value specified on the arguments or the query object

del(params)


function to delete rows of data

Arguments
  • params (object) - the criteria of which row to delete
Returns
  • (Array|Promise) - returns the number of rows deleted or the query object

getDB()


returns the knex object with table name

Returns
  • (Promise) - similar to knex(TABLE_NAME) that can be chained

getJoinDB()


returns the knex object table name with alias to make it easier to join

Returns
  • (Promise) - similar to knex(TABLE_NAME).as(alias) that can be chained

getConn()


returns the knex object

Returns
  • (Promise) - similar to knex()

Testing

Work in progress

Feedback

All bugs, feature requests, pull requests, feedback, etc., are welcome. Create an issue.

License

MIT