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

node-ar

v0.0.1

Published

A simple nodejs module as active-record does

Downloads

3

Readme

node-ar

Purpose

A simple ActiveRecord like nodejs module

It supports 'has_many' and 'belongs_to' relationship

You can find and find_by* each field name

Important: it works synchronously.

Introduction

This module is based on Sannis's node-mysql-libmysqlclient. Node-Ar adds some simple features as ActiveRecord does. I want to explain that it is not completed. This should be considered an example. But I would to expand it also with your help.

So, do not hesitate to contact me for any question or doubts

My mind is open for any collaboration ;)

Installation

For installing this module try

npm install node-ar

Usage

See file in the spec folder for examples

Overview

Having a DB as ActiveRecord on Rails wants. You can able to perform select insert and update using Models like instances.

DataType (used to declare the fields)

DataType.String # the VARCHAR type DataType.Int # the INT type DataType.Boolean # the TYNINT type (tmporarly incompleted)

Model

(Static methods) Model.find( id /* as NUM */ ) # returns the instance of the model if found. Otherwise null Model.find( 'all' ) # returns an Array instance contaning all model found by performing the select. Empty array if no record found Model.find( 'first' ) # returns the instance of the model representing the first matched record if found. Otherwise null Model.find_by( where, options, limit ) # where (Object) javascipt where = { field_foo_name: field_foo_value, field_bar_name: field_bar_value, } # options (Object) javascript options = { includes: ['table_foo_name', 'table_bar_name'], joins: { table_foo_name: { // INNER JOIN table_foo_name field_bar_name: { // ON field_bar_name table_xxxx_name: 'field_xxxx_name' // = table_xxxx_name.field_xxxx_name } } } } # limit (Number) Used as LIMIT sql condition

Model.find_by_foo_field_name( value ) # return an Array containing the result of select * from table_foo_name where FOO_FIELD_NAME = VALUE. A Model single instance if field id declared as unique

Todo

What i'm going to add:

  • Implement events

  • Fields validation

  • BUG: it doesn't delete the has_many relations while deleting a Model from DB. But I'm working to fix it.

  • More documentation is coming... ;)