sails-cubejs-glue

1.0.0 • Public • Published

Sails CubeJS Glue

npm version Coverage Status node npm bundle size

this package is intended to make a glue for cubejs and sails framework.

With this method, you can still use sails's functionalities like policy as it is.

Installation

to install is just straight forward:

  • with npm: npm i sails-cubejs-glue
  • with yarn: yarn add sails-cubejs-glue

Example Action

this is lazy method, that do everything one the action. (bootstrap and proxying).

Althought its better idea to use sails's hook for bootstrapping and action only proxying, this example is enough:

ON api/controllers/cube.js:

/* api/controllers/cube.js */
 
var glue = require('./sails-cubejs-glue');
 
var cubeApp = null;
const schemas = [
  {
    fileName: 'Orders.js',
    content: `
      cube('Orders', {
        sql: 'SELECT * FROM orders',
        measures: {
          countAll: {
            type: 'count'
          },
        }
      });
    `
  }
]
 
 
module.exports = async (req, res) => {
  if (cubeApp === null) cubeApp = await glue.bootstrap(schemas, {basePath: '/cube'});
 
  glue.createProxy(cubeApp)(req, res);
}
 

ON config/routes.js add the graphql route:

module.exports.routes = {
  ...
  '/cube/*': { action: 'cube' },
};
 

Connecting to Database

As cubejs's documentation: https://cube.dev/docs/connecting-to-the-database.

Example in environment variables:

CUBEJS_DB_TYPE=mongobi
CUBEJS_API_SECRET=123123
CUBEJS_DB_HOST=localhost
CUBEJS_DB_PORT=3307
CUBEJS_DB_USER=
CUBEJS_DB_PASS=
CUBEJS_DB_NAME=app

Drivers Dependencies

quoted from @cubejs-backend/server-core/core/index.js

const DriverDependencies = {
  postgres: '@cubejs-backend/postgres-driver',
  mysql: '@cubejs-backend/mysql-driver',
  mssql: '@cubejs-backend/mssql-driver',
  athena: '@cubejs-backend/athena-driver',
  jdbc: '@cubejs-backend/jdbc-driver',
  mongobi: '@cubejs-backend/mongobi-driver',
  bigquery: '@cubejs-backend/bigquery-driver',
  redshift: '@cubejs-backend/postgres-driver',
  clickhouse: '@cubejs-backend/clickhouse-driver',
  hive: '@cubejs-backend/hive-driver',
  snowflake: '@cubejs-backend/snowflake-driver',
  prestodb: '@cubejs-backend/prestodb-driver',
  oracle: '@cubejs-backend/oracle-driver',
};

License

MIT

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i sails-cubejs-glue

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    6.16 kB

    Total Files

    5

    Last publish

    Collaborators

    • xprycker