# gsql

> Simplified Sequelize and GraphQL models

Latest version **1.1.6** (published 2016-06-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install gsql
pnpm add gsql
yarn add gsql
bun add gsql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2016-06-25 |
| First published | 2016-06-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Neil Molina |
| Maintainers | getneil |

## Links

- npm: https://www.npmjs.com/package/gsql
- Repository: https://github.com/getneil/gsql
- Homepage: https://github.com/getneil/gsql#readme
- Issues: https://github.com/getneil/gsql/issues
- npm.io page: https://npm.io/package/gsql

## Dependencies (7)

- [graphql](https://npm.io/package/graphql.md) ^0.6.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.0
- [sequelize](https://npm.io/package/sequelize.md) 3.23.3
- [underscore](https://npm.io/package/underscore.md) ^1.8.3
- [require-dir](https://npm.io/package/require-dir.md) ^0.3.0
- [toposort-class](https://npm.io/package/toposort-class.md) ^1.0.1
- [graphql-sequelize](https://npm.io/package/graphql-sequelize.md) ^2.0.2

## Recent versions

- 1.1.6 (latest) — 2016-06-25
- 1.1.5 — 2016-06-25
- 1.1.4 — 2016-06-24
- 1.1.3 — 2016-06-24
- 1.0.3 — 2016-06-20
- 1.0.2 — 2016-06-19
- 1.0.1 — 2016-06-18
- 1.0.0 — 2016-06-07

## README

# GSQL
Simplified Sequelize and GraphQL models

### Table of Contents
- **[Features](#features)**
- **[Installation Instructions](#installation-instructions)**
- **[Usage Instructions](#usage-instructions)**
- **[Next Steps](#next-steps)**
- **[Dependencies](#dependencies)**

## Features
- define sequelize and graphql objects w/ one definition pattern
- simple way to create graphql schema

## Installation Instruction
```
npm install gsql
```
to save in package.json as a dependency
```
npm install --save gsql
```

## Usage Instructions
[Example App](https://github.com/getneil/gsql/tree/develop/sample)
```
var gsql = require('gsql'),
  sequelize = require('sequelize');

// simple sequelize initialization
var sampleApp = new gsql('DATABASE_NAME', 'username', 'password', {
  host: '127.0.0.1',
  dialect: 'postgres',
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  }
});

// has 1:1 relationship with UserProfile
sampleApp.define('User',{
    description: 'A person using the app.',
    attributes:{
      id: {
        type: sequelize.INTEGER,
        primaryKey: true,
        description: 'unique identifier of the user.'
      },
      email: {
        type: sequelize.STRING,
        unique: true,
        description: 'a way for the user to receive notification if not logged in.'
      },
      profile: {
        hasOne: 'UserProfile', // refers to the name of user
        foreignKey: 'userId'
      }
    },
    config:{
      tableName: 'users',
      freezeTableName: true,
      hooks:{
        beforeCreate: function(user, options){
          user.email = user.email.replace('@','-');
          // transform the data
        }
      }
    }
});
sampleApp.define('UserProfile',{
    description: 'The first name and last name of the user.',
    attributes:{
      id: {
        type: sequelize.INTEGER,
        primaryKey: true,
        description: 'unique identifier of the user.'
      },
      firstName: {
        type: sequelize.STRING,
        description: 'First Name description.'
      },
      lastName: {
        type: sequelize.STRING,
        description: 'Last Name description.'
      },
      userId: {
        type: sequelize.INTEGER,
        belongsTo: 'User'
      }
    }
});

// This will link objects using relationships belongsTo, hasOne, hasMany and belongsToMany
// there is an example app provided just check it out  https://github.com/getneil/gsql/tree/develop/sample
sampleApp.modelManager.associateObjects();

// will alter the database using Sequelize sync({force:true})
// returns a promise
sampleApp.modelManager.initializeDatabase()
.then(function(){
  // maybe you want to make some seed data?

  var User = sampleApp.models.User.sequelize
    , UserProfile = sampleApp.models.UserProfile.sequelize;

  sampleApp.models.User.sequelize.create({
    email: 'user@gmail.com',
    profile: {
      firstName: 'Karl',
      lastName: 'Marx'
    }
  },{
    include: [UserProfile]
  }).then(function(){
    console.log("data created!")
  });

})


var graphqlSchema = sampleApp.defineGraphqlSchema({
  user: {
    type: 'User'
  },
  users:{
    type: 'User',
    list: true
  }
});

const graphqlHTTP = require('express-graphql');
const app = require('express')();

app.use('/graphql', graphqlHTTP({
  schema: graphqlSchema,
  graphiql: true
}));

app.listen(3000);


```

## Next Steps
- be able to use custom GraphQL resolvers
- be able to add dependency to the same model
- etc maybe you have a request?

## Dependencies
- [Sequelize](http://docs.sequelizejs.com/en/latest/)
- [GraphQL](https://github.com/facebook/graphql)
- [graphql-sequelize](https://github.com/mickhansen/graphql-sequelize)

---
_Source: https://npm.io/package/gsql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
