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

swint-query

v1.2.5

Published

SQL query generator for Swint

Downloads

256

Readme

swint-query

Greenkeeper badge MySQL query generator for Swint

Warning: This is not the final draft yet, so do not use this until its official version is launched

Installation

$ npm install --save swint-query

Manager

  • Overall manager of ORM's
  • Usage
var manager = swintQuery.Manager({
		dir: path.join(__dirname, 'models'),
		mysql: {
			host: 'myhost.example.com',
			database: 'mydb',
			user: 'username',
			password: 'mypasswd'
		}
	}, function(err) {
		print(manager.models); // Models fetched from DB server
		done();
	});

Structure

  • Defining the model's structure
  • Usage
var defs = {
		name: 'foo',
		engine: 'MySQL',
		table: 'foos'
	},
	schema = [
		{
			field: 'bars',
			type: 'RelN:M',
			related: 'bar',
			joinTable: 'foos_bars',
			myKey: 'foo_id',
			relKey: 'bar_id'
		},
		{
			field: 'bazs',
			type: 'Rel1:N',
			related: 'baz',
			joinTable: 'bazs',
			myKey: 'foo_id'
		},
		{
			field: 'qux',
			type: 'RelN:1',
			related: 'qux',
			relKey: 'qux_id'
		}
	];

module.exports = function(manager) {
	defs.db = manager.mySqlConn;
	return swintQuery.Structure(manager, defs, schema);
};

Model

  • Methods

    • .query(query, callback)

      • Executes query
      • query: String, the query to be executed
      • callback: Function
    • .query(preparedQuery, params, callback)

      • Executes prepared query
      • preparedQuery: String, the query to be executed
      • params: Array
      • callback: Function
    • .save(data, callback)

      • Insert data if the data doesn't have id, or update data if it has.
      • data: Object or Array, If array, it must be the array of objects to be saved
      • callback: Function
    • .fetch(condition, option, callback)

      • condition: Object, the key is the name of field
      • option: Object
        • target: Array, the list of fields to be fetched, can be * or joinedModel.*.
        • join: Array, the list of the names of models to be joined
        • order: String or Array, the name of the field to be sorted, can be Array.
        • orderFlag: Boolean or Array, the sorting order
        • limit: Number, the number of rows to fetch
    • .queryPromise(query)

      • Executes query
      • query: String, the query to be executed
    • .queryPromise(preparedQuery, params)

      • Executes prepared query
      • preparedQuery: String, the query to be executed
      • params: Array
    • .savePromise(data)

      • Insert data if the data doesn't have id, or update data if it has.
      • data: Object or Array, If array, it must be the array of objects to be saved
    • .fetchPromise(condition, option)

      • condition: Object, the key is the name of field
      • option: Object
        • target: Array, the list of fields to be fetched, can be * or joinedModel.*.
        • join: Array, the list of the names of models to be joined
        • order: String or Array, the name of the field to be sorted, can be Array.
        • orderFlag: Boolean or Array, the sorting order
        • limit: Number, the number of rows to fetch
  • Usage

models.foo.fetch({
	myColumn: operator.ne('foo')
}, {
	target: ['*', 'bar.*'],
	join: ['bar'],
	order: 'myColumn',
	orderFlag: true,
	limit: 42
}, function(err, res) {
	// ...
});

Operator

  • Various operators
  • eq: Equal, { fieldName: eq(42) }
  • ne: Not equal, { fieldName: ne(42) }
  • gt: Greater than, { fieldName: gt(42) }
  • gte: Greater than or equal, { fieldName: gte(42) }
  • lt: Less than, { fieldName: lt(42) }
  • lte: Less than or equal, { fieldName: lte(42) }
  • btn: Between, { fieldName: btn(42, 84) }
  • nbtn: Not between, { fieldName: nbtn(42, 84) }
  • isNull: Is null, { fieldName: isNull() }
  • notNull: Not null, { fieldName: notNull() }