dbash

DBash

Tool for converting data between SQL and JS types easily. It’s more like a test library to see how npm packages work. Name inspired by Lodash - the ultimate JavaScript toolkit.

Installation

Installation is same for most of the Node.js packages:

# NPM
$ npm install --save dbash

# Yarn
$ yarn add dbash

DBash is also available from GitHub Package Registry.

Usage

// CommonJS
var _ = require('dbash');
console.log(_.sqlIntJsBool(1));

// ES2015
import { sqlIntJsBool } from 'dbash';
console.log(sqlIntJsBool(1));

// Also ES2015
import * as _ from 'dbash';
console.log(_.sqlIntJsBool(1));

Functions

Boolean

Integer

jsBoolSqlInt(input: boolean): number
// Takes JavaScript boolean and returns 1 or 0

sqlIntJsBool(input: number): boolean
// Takes SQL number and returns true or false

String

jsBoolSqlString(input: boolean): string
// Takes JavaScript boolean and returns 'true' or 'false'

sqlStringJsBool(input: string): boolean
// Takes SQL string and returns and returns true or false

Date

Date

jsDateSqlDate(input: Date): string
// Takes JavaScript Date and returns corresponding SQL Date string

sqlDateJsDate(input: string): Date
// Takes SQL DATE and returns corresponding JS Date object
// Accepts `2010-07-28` and `10-07-28` formats

DateTime

jsDateSqlDateTime(input: Date): string
// Takes JavaScript Date and returns corresponding SQL DateTime string

sqlDateTimeJsDate(input: string): Date
// Takes SQL DateTime and returns corresponding JS Date object
// Accepts `2010-07-28 11:12:13` and `10-07-28 11:12:13` formats