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

light-orm

v0.1.4

Published

Super simple ORM node.js wrapper for relational databases. It does not depends on any specific driver, so you can connect to mysql, ms server and so on... Try it!

Downloads

66

Readme

##Light-orm Light-orm - simple ORM node.js wrapper for relational databases. It does not depends on any specific driver, so you can connect to mysql, postgresql, ms server with your favorite driver.

Your db connector (or wrapper) just should implement the interface:

interface DriverInterface {
    query(query: string, handler: (err, rows, fields) => void);
}

This interface came from node-mysql driver, as most popular option, that lets you avoid writting your wrappers to connectors.

Light-orm gives you freedom in choising your own driver. You should not any more make meet half-way between high driver performance with native realization and ORM wrapper.

###Installation npm install light-orm

###Development Light-orm is written on typescript. Look for the sources here: lib/typescript and lib/compiler. You may find there comments in jsdoc style.

###Examples Example connection (mysql):

var mysql = require('mysql'),
	lightOrm = require('light-orm');

lightOrm.driver = mysql.createConnection(require('./connection.json'));
lightOrm.driver.connect();

Create collection for table name author:

var AuthorCollection = new lightOrm.Collection('author');

Find one model:

AuthorCollection.findOne({
	id: 1
}, function(err, model) {
	console.log(model.getAll());
	//{ id: 1, name: 'James Bond', description: 'Agent 007' }
});

Find one model by sql:

AuthorCollection.findOne("SELECT * FROM `author` WHERE id = 1", function(err, model) {
	console.log(model.getAll());
	//{ id: 1, name: 'James Bond', description: 'Agent 007' }
});

Find models:

CarCollection.find({
	category_id: 5
}, function(err, models) {});

Find models by sql:

CarCollection.find({
	category_id: 5
}, function(err, models) {});

Get all attributes:

model.getAll();

Get one attribute:

model.get('name');

Set attribute:

model.set('name', 'Oleksandr Knyga');

Set attributes:

model.set({
	name: 'Oleksandr Knyga'
});

Check attribute:

model.has('name');

Clear attributes:

model.clear();

Clear one attribute:

model.clear('name');

Get custom row by sql:

AuthorCollection.findOne("SELECT COUNT(*) as `count` FROM `author` WHERE name = '" + author.name + "'", function(err, data) {
	var count = data.get('count');
});

Save:

model.create(function(err, model) {});

Update:

model.update(function(err, model) {});

Update, with custom where block:

model.update({
	pkValue: {
		id: 31
	}
}, function(err, model) {});

Update, manual pk field name:

model.update({
		pk: ['id']
}, function(err, model) {});

Delete:

model.remove(function(err, model) {});

Delete, with custom where block:

model.remove({
	pkValue: {
		id: 31
	}
}, function(err, model) {});

Delete, manual pk field name:

model.remove({
		pk: ['id']
}, function(err, model) {});

If you do not want to have model in callback, add false as last argument to remove, update, create. Like this:

model.update({
	pkValue: {
		id: 31
	}
}, function(err, model) {}, false);

###Licence Copyright 2014 Oleksandr Knyga [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.