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

@hapiness/sequelize

v1.0.0

Published

Hapiness Module for SQL usage

Downloads

8

Readme

sequelize-module

Sequelize-module is a wrapper of sequelize and sequelize-typescript for the Hapiness Framework.

Table of contents

Using sequelize-module inside your Hapiness application

yarn or npm it in your package.json

// Using NPM
$ npm install --save @hapiness/core @hapiness/sequelize rxjs

// Using Yarn
$ yarn add @hapiness/core @hapiness/sequelize rxjs

Installing peer dependencies

According to sequelize documentation you will need to install at least one of these packages for sequelize-module to work:

# Using NPM
$ npm install --save pg@6 pg-hstore #pg@7 is currently not supported
$ npm install --save mysql2
$ npm install --save sqlite3
$ npm install --save tedious # MSSQL

# Using Yarn
$ yarn add pg pg-hstore
$ yarn add mysql2
$ yarn add sqlite3
$ yarn add tedious # MSSQL
"dependencies": {
    "@hapiness/core": "^1.3.0",
    "@hapiness/sequelize": "^1.0.0",
    "rxjs": "^5.5.3",
    // + one of these
    "mysql2": "^1.5.1",
    "pg": "^6.4.2",
    "pg-hstore": "^2.3.2",
    "sqlite3": "^3.1.13",
    "tedious": "^2.1.5"
    //...
}

Importing SequelizeModule from the library

This module provide an Hapiness extension for Sequelize. To use it, simply register it during the bootstrap step of your project and provide the SequelizeExt with its config

@HapinessModule({
    version: '1.0.0',
    providers: [],
    declarations: [],
    imports: [SequelizeModule]
})
class MyApp implements OnStart {
    constructor() {}
    onStart() {}
}

Hapiness
    .bootstrap(
        MyApp,
        [
            /* ... */
            SequelizeExt.setConfig(
                {
                    dialect: 'sqlite', // 'mysql'|'sqlite'|'postgres'|'mssql'
                    username: 'username',
                    password: 'password',
                    database: 'database',
                    storage: ':memory:' // Only for sqlite (path of the file or :memory:)
                    // ...
                }
            )
        ]
    )
    .catch(err => {
        /* ... */
    });

SequelizeExt needs an Option object so you can provide all the properties defined by Sequelize with the minimum of the options below:

interface Options {
    username: string;
    password: string;
    database: string;
    dialect: 'mysql'|'sqlite'|'postgres'|'mssql';
}

Models

Defining a model

Sequelize-module uses sequelize-typescript so you can define your models with classes in the form of sequelize-typescript models. However, for your Models to be integreted in your Hapiness application you need to decorate it with @TableModel:

import { Model, Table } from 'sequelize-typescript';
import { TableModel } from '@hapiness/sequelize';

@TableModel()
@Table
export class User extends Model<User> { }

NB: You need to either name your model's file the name of your + .ts (here user.ts) or you need to export your model as default: export default class User extends...

Injecting a model

To Inject a Model in your application you just need to pass it to the array of declarations of your @HapinessModule.

See examples directory for a basic working implementation. Run it with the command npm run dev:watch.

SequelizeClientService functions

To use sequelize, you need to inject inside your providers the SequelizeClientService.

class FooProvider {

    constructor(private _sequelize: SequelizeClientService) {}

    bar(): Observable<string> {
    	return this._sequelize.instance.model('MyModel');
    }
}

SequelizeClientService.instance this will return you the sequelize client and you will be able to call on it every sequelize commands (see the reference here)

Back to top

Maintainers

Back to top

License

Copyright (c) 2017 Hapiness Licensed under the MIT license.

Back to top