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

dbcover

v1.1.1

Published

A Promise/A+ Based Object Relational Mapping Module With Cache(Memcached/Redis) Enabled For Mysql/PostgreSQL/more. [under development]

Downloads

45

Readme

A Simple ORM Module

!UNDER DEVELOPMENT!

[] Improve cache system. [] Rewrite inner code with promise and simplify it.

GO TO ISSUES TO SEE KNOWN BUGS.

Install: npm install dbcover

Common Usage (in coffeescript):


{Observe, Model, Validators}   = require 'dbcover'
# Require whatever validator you need.
# List of validators: integer, string, email, required

# Define database connection
Observe.define 'repo',
  name: 'default'
  provider:
    type: 'mysql'
    options:
      host: 'localhost'
      port: 3306
      password: '123123'
      user: 'root'
      database: 'test'
      
Observe.define 'repo',
  name: 'pg'
  provider:
    type: 'postgresql'
    options:
      host: 'localhost'
      port: 3306
      password: '123123'
      user: 'root'
      database: 'test'

Observe.define 'cache',
  name: 'default'
  provider:
    type: 'redis'
    options:
      host: 'localhost'
      port: 6379

# Define an model
User = new Model
  meta:
    table: 'users'
    repo: 'pg'   # default repo name is 'default'
    cache: 'default' # leave meta.cache blank or set it false to disable caching
    ttl: 10  # cache expire time(seconds), must be set if cache is enabled for this model. if ttl < 1, then no expire time would be applied.
    fields: [
      # set auto to true to support auto increment columns
      {name: 'id', type: 'integer', auto: true, primkey: true, uniq: true}
      {name: 'email',   type: 'string', validator: 'email', primkey: true, uniq: true}
      {name: 'random_key', type: 'string', primkey: true}
      {name: 'age',     type: 'integer', validator: new Validators.integer(10, 100)}
      {name: 'extra',   type: 'json'}
      {name: 'created', type: 'timestamp'}
    ]
    # primkey(s) with one or more columns. remember to use the name you definded above, not the real column name.
    indices: [
      {name: 'pk', fields: ['email', 'age']}
    ]

  sayHi: () ->
    console.log 'hi'

  rename: (name, id)->
    deferred = Q.defer()
    raw_sql = "UPDATE #{@$table} SET name = ?, updated_at='#{new Date}' WHERE id = ?"
    # You may use @$repo.query to make customized queries.
    # Use ? or :var instead of raw variables to avoid SQL injection.
    @$repo.query raw_sql, [name, id], (err, result)->
      deferred.reject err if err?
      deferred.resolve result
    return deferred.promise

# Turn on debug, default is false
User.turnOnDebug(true)

# Creating instance
user = User.new
  userId: 23
  email: '[email protected]'
  age: 22

# Save instance 
promise = user.save()

# Updating attributes 
user.age = 23
user.extra = { nick: 'rankjie' }
promise = user.update()

# Deleting instance 
promise = user.delete()

# Count rows
promise = user.count()

# Count rows with WHERE age > 30
promise = user.count("age > 30")


# Query 
# All promises returned by Query or findBy, will be resolved with a set of instances ( first() and findByIndeices which has `uniq:true` will return just one object )
# Or, rejected with errors.
promise = User.findById(123)
# You can append '__gt' or '__lt' to the field name, that would equals to '>' and '<'
promise = User.find(age: 30, created__gt: 2334343).first()
promise = User.find(age__lt: 30, created: 2334343).first()
# Get all the entries
promise = User.find(age: 30).all()
# Find by primkeys 
promise = User.findByPk(userID: 234, age: 99)
# prim keys like random_key will be transformed to camel case like RandomKey
promise = User.findByRandomKey('someValue')


# list all the data
promise = User.find()
  .orderBy('created', 'desc')
  .all()

# list from 0 to 10
promise = User.find('age > ? and created > ?', [30, 234242])
  .orderBy('created', 'desc')
  .list(0, 10)

# get them all
promise = User.find('age > :age and created > :created')
  .set(age: 30, created: 1234324234)
  .orderBy('created', 'desc')
  .all()

# get the first one
promise = User.find('age > :age and created > :created')
  .set(age: 30, created: 1234324234)
  .orderBy('created', 'desc')
  .first()