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

jorma

v0.2.0

Published

JavaScript Object-relational mapping alchemy

Downloads

4

Readme

Jorma

NPM Downloads NPM Version Build Status

Jorma is an object-relational mapping for Node.js, which is heavily influenced by Active Record of Ruby on Rails. See the documentation for detail.

Requirements

Currently, Jorma only supports MySQL (and variants such as MariaDB) database.

Usage

Assume the tables of posts, users, and comments were setup already. We may declare the models as classes extended from the base class Bone of Jorma. After the models are connected to the database using connect, the columns of the tables are mapped as attributes, the associations are setup, feel free to start querying.

const { Bone, connect } = require('jorma')

// define model
class Post extends Bone {
  static describe() {
    this.belongsTo('author', { Model: 'User' })
    this.hasMany('comments')
  }
}

async function() {
  // connect models to database
  await connect({ host: 'example.com', models: [Post], /* among other options */ })

  // CRUD
  await Post.create({ title: 'New Post' })
  const post = await Post.findOne({ title: 'New Post' })
  post.title = 'Untitled'
  await post.save()

  // or UPDATE directly
  await Post.update({ title: 'Untitled' }, { title: 'New Post' })

  // find with associations
  const postWithComments = await Post.findOne({ title: 'New Post' }).with('comments')
  console.log(post.comments) // => [ Comment { id, content }, ... ]
}

Syntax Table

| JavaScript | SQL | |-----------------------------------------|----------------------------------------------------| | Post.create({ title: 'New Post' }) | INSERT INTO posts (title) VALUES ('New Post') | | Post.all | SELECT * FROM posts | | Post.find({ title: 'New Post' }) | SELECT * FROM posts WHERE title = 'New Post' | | Post.find(42) | SELECT * FROM posts WHERE id = 42 | | Post.order('title') | SELECT * FROM posts ORDER BY title | | Post.order('title', 'desc') | SELECT * FROM posts ORDER BY title DESC | | Post.limit(20) | SELECT * FROM posts LIMIT 0, 20 | | Post.update({ id: 42 }, { title: 'Skeleton King' }) | UPDATE posts SET title = 'Skeleton King' WHERE id = 42 | | Post.remove({ id: 42 }) | DELETE FROM posts WHERE id = 42 |

A more detailed syntax table may be found at the documentation site.

Migrations

Currently, Jorma doesn't provide a way to do database migrations. There are two popular approaches:

  • A separated migration DSL and database metadata, like Active Record.
  • A detailed enumeration of attributes and types in the models, like Django.

There is a third way, which is the very reason Jorma has yet to implement migrations, that the database can be designed through a third-party service. It can be an ER designer, a GUI software for MySQL, or a MySQL-compliant database in the cloud.

But I'm sure we'll get to that.