0.1.3 • Published 4 years ago

sequelize-as-json v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

sequelize.json: a simple way to jsonify your mysql

Sequelize.json is a module that enables your tables to be flexible to json, is a very practical way to use and is very useful in projects.

It has a basic and short api, follow the example below for more details:

const Sequelize = require('sequelize');
const SequelizeJSON = require('sequelize.json');

const database = new Sequelize('mysql://root@localhost:3306/database');
const members = database.define('members', {
    id: {
        type: Sequelize.INTEGER,
		autoIncrement: true,
		primaryKey: true,
    },
    
    username: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    
    informations: {
        type: JSON, // You need to use JSON as type for the module to automatically identify the object (later will be replaced with TEXT)
        
        defaultValue: '{"im":"a data"}', // Optional, you default value.
    }
});

database
    .authenticate()
    .catch(console.error)
    .then(async () => {
        const member = await members.findOrCreate({
            defaults: { username: 'Darkzinho' },
            where: { username: 'Darkzinho' },
        }).then(results => results.shift());
        
        console.log('Voila, my name is', member.username);
        console.log('My information json before was', member.informations);
        
        member.informations = {
            number: ~~(Math.random() * 2000)
        };
        
        await member.save():
        console.log('Now it is', member.informations);
    });

WARNING & LICENSE

This project actually use MIT license and can be verified in LICENSE file. I'll update this project only when I find some critical problem, you can fork and update yourself if I don't.

Please report your issue usages.

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago