mysql-typesdeprecated

maps js types to mysql types

Usage no npm install needed!

<script type="module">
  import mysqlTypes from 'https://cdn.skypack.dev/mysql-types';
</script>

README

Usage

var mysqlType = require('mysql-types');

Conversions

JS Type MySQL Type
string VARCHAR (automatically converted to TEXT when adding more characters)
number SMALLINT
boolean TINYINT(1)
date DATETIME
function tries if function is constructor and uses type of instance else Error
object Error
array Error

Examples

let string = mysqlType('string') // VARCHAR
let string = mysqlType(String) // VARCHAR

let number = mysqlType(123) // SMALLINT
let number = mysqlType(Number) // SMALLINT

let date = mysqlType(new Date()) // DATETIME
let date = mysqlType(Date) // DATETIME

let bool = mysqlType(true) // TINYINT(1)
let bool = mysqlType(Boolean) // TINYINT(1)