1.3.7 • Published 5 years ago

mssql-constants v1.3.7

Weekly downloads
12
License
ISC
Repository
github
Last release
5 years ago

mssql-constants

Dependencies

Consumption

This module writes a directory of enumerable constants based on SQL tables. All constant files are meant to be easily read. The goal here is to maintain dryness within the SQL environment. To me, this is ensured by deriving our constants directly from the SQL layer.

Example

var mssqlConstants = require('mssql-constants');

mssqlConstants.createConstantFiles(
  {
    // SQL details, required to query tables
    database: configuration.sql_database,
    password: configuration.sql_password,
    server: configuration.sql_server,
    user: configuration.sql_user
  },
  // Directory to write constants into
  __dirname + '/constants',
  [
    // Each table definition corresponds to a constant file
    // If multiple value columns are specified, the file will export a dictionary of enums
    // If just one value column is specified, the file will export the enum directly
    mssqlConstants.tableDefinition({
      file: 'locations',
      table: 'Locations',
      keyColumn: 'locationName',
      valueColumns: [
        'city',
        'state',
      ]
    }),
    mssqlConstants.tableDefinition({
      file: 'country',
      table: 'Countries',
      keyColumn: 'countryName',
      tableFilter: function(row) { return row.fieldVal === 'WhatWeWant'; },
      keyTransform: CONSTANT_FORMAT,
      valueColumns: ['countryID']
    }),
  ],
  function(err) {
    if (err) {
      console.warn(err);
      return process.exit(1);
    }
    return process.exit(0);
  }
);

function CONSTANT_FORMAT(str) {
  return "'" + str.toUpperCase().replace(/ /g, '_') + "'";
}
1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.7

7 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago