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

nano-orm

v0.7.4

Published

Tiny wrapper layer for loading and persisting models to databases with promise based interface

Downloads

7

Readme

Nano ORM

Tiny wrapper layer for loading and persisting Models from SQL databases using a Q promise based interface

Build Status Coverage Status

PRERELEASE

WARNING: This package is currently in prerelease - the API may or may not change before final release

The package number will be bumped to 1.0.0 for the initial release, todo before then:

  • Release any-db-q
  • Test usage of this in a real project
  • Explore concept of extensions (mini-modules that add methods to the prototypes of models to offer enhanced functionality)
  • Auto-updated created_at and modified_at fields

Motivation and Who is This For?

Many ORM libraries are heavyweight complex beasts that attempt to provide 'helpful' utilities to generate SQL queries, represent relationships between the models in the application, etc, typically in order to avoid having the programmer ever write plain SQL queries.

However, assuming the application's developers:

  • Are competent with plain SQL
  • Control the environment in which the application is deployed (IE: what database is in use)
  • Don't plan on changing to a different database

The advantages touted by such libraries don't seem all that attractive. Indeed there is no need to have the code be compatible with every database under the sun, and learning the constructs specific to the ORM is simply an additional burden placed on the developer, who would be more comfortable writting the SQL queries directly. This can also lead to more performant code without layers of abstraction hiding what is really going on.

Under these assumptions, the main benefit of a traditional ORM is avoiding tedious boilerplate for loading and persisting models from the database. It is this that Nano ORM attempts to avoid - with any intresting functionality unique to the app being provided by the application's developer extending the model's created by Nano ORM with their own functions and utilities built using plain SQL.

Basic Usage

let AnyDb               = require('any-db');
let nano_orm            = require('nano-orm');
let DbConnectionPromise = require('db-connection-promise');

// Define the model, wraps the 'user' table in the database, with columns 'email' and 'password'
let User = nano_orm.defineModel('user', ['email', 'password']);

let connection = AnyDb.createConnection({ adapter: 'sqlite3'});
let dbh = DbConnectionPromise(connection);

// Load the row with id 1 from the database
User
	.load(dbh, 1)
	.then((user) => {
		// Modify the instance
		user.email = '[email protected]';

		// Persist the changes to the database
		return user.save(dbh);
	});
});

More complete examples can be found in the /examples directory.

Features

  • Load/Persist model instances to/from database
  • Load all instances in DB meeting some criteria, represented with standard SQL WHERE syntax
  • Create instances from raw rows returned from the database by a custom SQL query

Planned

  • Auto-updated 'created_at' and 'updated_at' fields
  • Load instances with IDs in some set