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

mynodefy

v2.0.3

Published

A performatic and secure NodeJS' MySQL ORM

Downloads

5

Readme

CircleCI Codecov

MyNodefy

A NodeJS's ORM designed for designers. And, based on PHP's Doctrine.

First things first

Before you can use it good, you must define and configure some informations.

Connection

You must define your connection informations before you could really start.

    const mynodefy = require('mynodefy');

    mynodefy.Connection.define('host', 'username', 'password', 'database');

Entity

You can configure your entity by returning an object of informations on rule method. It's not required unless you strictly want MyNodefy to validate your information before it persists onto database.

You can also pass information about database table name that is being represented by the Entity using method tableName. In case this method doesn't exists, entity name is used in plural form.

    class MyEntity
    {

        tableName()
        {
            return 'table_name';
        }

        rules(
            return {
                id: { type: 'integer', key: 'primary' },
                name: { type: 'varchar', size: 100, null: false },
                age: { type: 'integer', size: 3, null: true }
            };
        )

    }

Repository

Your Repository will work accordling to data configured on Entity. But, you can create your own repository and add method respective to your business rules.

    const Repository = require('mynodefy').Repository;

    class MyRepository extends Repository {}

    let repo = new MyRepository(MyEntity);

    repo
        .find()
        .first()
        .then(entity => {
            //Do something with entity
        });

Querying

In MyNodefy you can query wanted data from basic to advanced. You can get filtered data in three ways:

All

Will return everything the table has filtered but without limit and offset.

    repo.find()
        .all()
        .then(collection => {
            //Do something
        });

Get

Works like All method but let you paginate collection with limit and offset

    repo.find()
        .get()
        .then(collection => {
            //Do something
        });

First

Get the first data that satisfies filters

    repo.find()
        .first()
        .then(entity => {
            //Do something
        });

Filtering

There are tow ways for filtering data:

By

Searching for value exactly equal filter. Recommended when searching by id

    repo.find()
        .by('name', 'George Clooney')
        .get()
        .then(collection => {
            //Do something
        });

Where

To make a well and more elaborated query that needs advanced filtering, it's strongly recommended to use where. As in the example below you can use too Expression class, that let you do comparision between fields.

    const Expression = require('mynodefy').ORM.Query.Expression;

    let expr = new Expression();

    repo.find()
        .where.and(expr.like('address', 'Paulista Av.'))
        .where.or(expr.like('address', 'Marginal Pinheiros'))
        .get()
        .then(collection => {
            //Do something
        });

Saving

To save an entity, you must just fill it respecting it's rules and pass to method save that is responsible for checking if Entity will be inserted or updated.

PS.: After insertion, Repository detects Entity ID and auto update it.

    let entity = new MyEntity();
    entity.name = 'Mariah Carey';
    entity.job = 'Singer';
    entity.age = 42;

    repo.save(entity)
        .then(response => {
            //Response will be true or false
        });

Association

Conclusion

Sorry if you feel frustrated seeing this document. But, documentation is being developed as long as project is being developed too.