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

modelar

v3.2.4

Published

An expressive ORM with query builder and supports multiple databases.

Downloads

56

Readme

Modelar

An expressive ORM with query builder and supports multiple databases.

See API documentation on official website. Or on GitHub Pages.

Prerequisites

  • NodeJS version higher than 4.0.0.

Install

To install Modelar in you project, just type the following command in your shell or CMD:

npm install modelar --save

Supported Databases

This module currently supports these databases:

Not all adapters are installed automatically, only MySQL/MariaDB (since 3.0.4) are internally included, you must manually install other adapters if you want to use them.

What can I do with this module?

  • Write less code.
    • You can just define a class that extends the Model, and most of the work would be done for you.
    • Promise guarantees that all the procedures can be controlled within one logic.
  • Write expressive and good looking code.
    • Attributes of a model is actually properties of the instance.
    • All setter and getter supports.
  • Write one piece of code, run everywhere.
    • Modelar exposes a common API that provides consistency across databases.
    • You can just write a piece of code, and run it with all the databases supported, and don't have to worry the behavior of different databases.
  • Use Query Builder to handle data.
    • This module provides most of the SQL supports to the Model.
    • Query builder provides an Object-Oriented way to generate SQL statements.

Modelar is still growing, more features might be introduced in future versions.

Example

const { DB, Model } = require("modelar");

DB.init({
    type: "mysql", // Could be 'mysql', 'maria' or 'postgres' by default.
    database: "modelar",
    host: "127.0.0.1",
    port: 3306,
    user: "root",
    password: "161301"
});

// Add a global event handler to every queries.
DB.on("query", model=>{
    console.log(model.toString())
});

// Define a new class that extends the Model.
class Article extends Model {
    constructor(data = {}) {
        super(data, {
            table: "articles",
            primary: "id",
            fields: [ "id", "title", "content" ],
            searchable: [ "title", "content" ]
        });
    }
}

(async () => {
    var db = null;
    try {
        db = new DB();

        // Create a new table `articles`:

        var table = new Table("articles");
        table.addColumn("id").primary().autoIncrement();
        table.addColumn("title", "varchar", 255).notNull();
        table.addColumn("content", "varchar", 1024).notNull();

        table = await table.use(db).save();
        console.log(table);
        console.log("");

        // Insert an article into the database with 'Article' model:
        
        var article = new Article;
        article.title = "A new article in Modelar circumstance.";
        article.content = "This is the content of the article.";
        
        article = await article.use(db).save();
        console.log(article);
    } catch (e) {
        console.log(e);
    }

    if (db)
        db.close();
})();

Above gives a very simple example that shows the convenience and expressive functionality that this package carries, you can go into the real depth of it by checking the API documentation.

This package is written in TypeScript and compiled to ES5 standard (since 3.0.4) with some ES2015 features, so it can run in any version of NodeJS that higher than 4.0.0. But this feature relies on the support of the adapter you're using, so check the specification of the adapter carefully.