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

sn-persist

v0.1.4

Published

Persistence module for mysql & mongo.

Downloads

1

Readme

sn-persist

Easily persist node.js objects with MySQL, SQLite or Mongo.

Intro

Sn-persist adds an easy(ish) to use persistence tier to your node.js applications. It provides a regular interface between your application and common database drivers. Application developers use a simple JSON object to describe the schema of a database table or collection; sn-persist reads this description and creates a data access object to create, read, update and delete records in the collection.

Sn-persist is not an object-relational mapping package. It does not build a SQL table or Mongo collection from your object definitions. You still have to define the structure of tables or collections. But it does handle the mundane tasks of creating tables, building accessors and managing the connection to the database.

Though you still need to have knowledge of the underlying database technology, it does move database specific features into a declarative JSON initialization object. Application developers provide SQL or Mongo-specific setup data during initialization, but during steady state usage, a implementation-independent API is used to access data from the persistence tier.

Also, sn-persist binds records in a table (or collection) to a prototype object so database reads return objects with behavior, not blank maps of field-names to data.

Please note that sn-persist trades expressiblity for convenience. In reducing the complexity of dealing directly with the database, there are some complex database schemas which cannot be effectively modeled with this package. However, we have noted it effectively models the vast majority of database tables we have wanted to use. If you are building a simple or moderately complex web application, sn-persist is probably still a net win. In short, if you're not using a complex database schema, you won't miss what you aren't using.

Simple Example

What follows is a simple example of using sn-persist with MySQL. You might notice a few things about it. First off, it's kind of long for a "simple" example. Mea Culpa. But in my defense, let me remind you that a) there are a lot of comments, b) there's a fair amount of setup and c) it's not like database access has ever been a one or two line activity.

What we see in this example is:

  1. Setting up the persistence instance
  2. Building a model class to hold info we cribbed from the database and define it's behavior.
  3. How to use the DAO object returned from the init() call to access elements in the database.
  4. How to close down a database connection