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

sequelize-six

v0.0.9

Published

Library to build Sequelize models using ES6 code

Downloads

15

Readme

Sequelize Six

travis-ci Stories in Ready

ALPHA WARNING

This library doesn't currently work, its a work in progress. However enough exists for you to play with and help develop!


Overview

Sequelize.js is a fantastic ORM for SQL databases. The one pitfall is that it is not very ES6 friendly in the way you have to declare classes. This library offers some utilities to help make it easy to write your schemas in ES6 syntax with the help of ES7 decorators.

Requirements

  • Babel.js with --stage 0 flag
  • Sequelize.js

Class Decoration Syntax

import { Model } from 'sequelize-six';
import Sequelize from 'sequelize';

class User extends Model {
  username = { type: Sequelize.STRING };
  firstName = { type: Sequelize.STRING };
  lastName = { type: Sequelize.STRING };
}

export User.exportModel();

Instance methods and Class methods

All class instance methods are automatically added to the instance methods of the schema. Methods marked as static will be added to class methods of the schema.

Getters and Setters

Using the get and set syntax is all you need to add getters and setters to your class. If you want to have a getter or setter interact with a specific field, you can prefix the method name with an underscore. Here's an example:

class Menu extends Model {
  name = { type: Sequelize.STRING };
    
  get _name () {
    return this.getDataValue('name');
  }
    
  set _name ( value ) {
    this.setDataValue('name', value);
  }
}

Validations

WIP

Hooks

WIP

Extending Models

Its common to want to be able to create functionality that is common between multiple models, but that isn't necessarily stored in a single database. A prime example of this would be a location model that stores addresses and latitude and longitudes. Both users and businesses models might need location data. Instead of recreating logic in both models, you can use model extension.

@extend( Location )
class User {
  ...
}

All the fields, methods, hooks, validations, etc of the location model are carried down into the User model. User model is the primary model so if you want to overwrite a method for specific class you can redeclare the method in User and it will take precedence over that of Location.

Helper Decorators

There is an @enumerable and @readOnly decorator in this library that are only used to prevent the model generator from adding those fields/functions into the final schema. The main purpose of these helpers is to prevent functions of the Model base class from being added to the Schema's that are derived from it. There may be applications for external use so they are included in the library.

Development

We actively encourage developers to participate in helping us make this library better. Please fork this repository and after cloning run npm install. We use eslint to lint our project so if you run gulp lint you'll get the feedback from this. npm test will run our test library.

Make sure you're writing tests to cover your new code additions and then submit a pull request.

Thanks!