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

h-orm

v0.0.11

Published

H-orm is a mysql orm for nodejs

Downloads

6

Readme

h-orm

H-orm is a mysql orm for nodejs

H-orm is also meaning happy and easy to use

Usage example

Here is an example how to use h-orm

const horm = require('h-orm')

horm.connect({
    limit: 10,
    host: '127.0.0.1',
    port: '3306',
    database: 'test',
    user: 'your username',
    password: 'your password',
    debug: true
})

const StudentModel = horm.model('teacher', {
    name: String,
    sex: Number,
});

(async () => {
   console.log(await StudentModel())
   console.log(await StudentModel().find(1))
   console.log(await StudentModel().create({sex: 0}))
   console.log(await StudentModel().delete({sex: 0}))
   console.log(await StudentModel().update({sex: 0}, {id: 1}))
})()

Api

horm

connect(config)

Create a mysql connect pool, you can set follow setting

{
    limit           : 10 // default 10, pool max connect num 
    host            : '127.0.0.1',
    port            : '3306',
    user            : 'your username',
    password        : 'your password',
    database        : 'your database',
    debug           : true // trun on this debug you will see all sql
}

model(tabname, schema, exInfo)

You will get a model instance after use model function

const hormInstance = horm.model('student', {
	name: String,
	sex: Number
})

How about exInfo?

You can use exInfo set some default setting

{
  status: 'status',  // when use delete , really change field ( 0 || 1) , 'status' is default value
  pri: 'id' // table pri, 'id' is default value 
}

hormInstance

hormInstance()

Get all schema from table

(async () => {
  await hormInstance() 
})()

create(data)

Create one data or more

(async () => {
  await hormInstance().create({name: 1})
  await hormInstance().create([{name: 1}, {name: 2}])
})()

delete(data)

Delete some data which name = 1 or prikey = 1

(async () => {
  await hormInstance().delete({name: 1})
  await hormInstance().delete(1)
})()

update(changeData, whereDate)

Update data

(async () => {
  await hormInstance().update({name: 1}, {sex: 0})
})()

find(data)

Find prikey = 1 or prikey in (1,2,3)

(async () => {
  await hormInstance().find(1)
  await hormInstance().find([1,2,3])
})()

where(serachData, mode)

Find info which include serachData (suport like)

(async () => {
  await hormInstance().where({sex: 0})
  await hormInstance().where({sex: [0, 1]})
  await hormInstance().where({sex: 0, name: '%n'}, 'OR')
  await hormInstance().where({name_like: '%ma%'}) // SQL LIKE
  await hormInstance().where({name_not_like: '%ma%'}) // SQL NOT LIKE
})()

like(serachData, likeMode, linkMode)

Use SQL like syntax Find info which include serachData

(async () => {
  await hormInstance().like({name: '%ma%'})
  await hormInstance().like({name: 'm%'})
  await hormInstance().like({name: '%n', sex: 1}, 'NO', 'OR'))
})()

sort(data)

Sort your data

(async () => {
    await hormInstance().sort({key: 'name': rule: 'ASC'})
    await hormInstance().sort([{key: 'name': rule: 'ASC'}, {key: 'sex': rule: 'DESC'}])
})()

limit(num, count)

Return limit result

(async () => {
  await hormInstance().limit(10) // get 0-9
  await hormInstance().where({sex: 0}).limit(1)
  await hormInstance().where({sex: 0}).limit(0, 5) // get 0-4
})()

License

MIT