GithubHelp home page GithubHelp logo

yup-sql's Introduction

yup-sql

Point it at your local database, and it spits out a Yup object validator.

Build Status

This is a straight fork of joi-sql

Install

npm install yup-sql

(npm install -g yup-sql if you want to use it from the command-line)

The only "breaking" change from 1.x to 2.x is that support for versions of node older than 12 was dropped.

Usage

CLI

yup-sql --host=localhost --user=root --password=abc123 --schema=awesomedb --table=customer --camel

host, user, password, and camel are all optional. schema and table are not.

If camel is set, then column names are converted to camel case identifiers.

Spits out something like:

yup.object({
	projectId: yup.number().integer().min(0).max(4294967295).nullable(false),
	contactId: yup.number().integer().min(0).max(4294967295).nullable(false),
	dateCreated: yup.date().nullable(false),
	engineerId: yup.number().integer().min(0).max(4294967295).nullable(true),
	name: yup.string().max(200).nullable(false).default(''),
	engineeringProject: yup.boolean().nullable(false).default(1),
	printingProject: yup.boolean().nullable(false).default(1),
	activeProjectStateId: yup.number().integer().min(0).max(4294967295).nullable(false),
	startDate: yup.date().nullable(true),
	done: yup.boolean().nullable(false).default(0),
	doneDate: yup.date().nullable(true),
	deadReason: yup.string().max(65535).nullable(true).default(''),
	quotedEngineeringHours: yup.number().lessThan(10000).nullable(true).default(0),
	actualEngineeringHours: yup.number().lessThan(10000).nullable(true).default(0),
	engineeringDueDate: yup.date().nullable(true),
	printParts: yup.string().max(65535).nullable(true),
	printQuantity: yup.number().integer().max(16777215).nullable(true).default(1),
	printTimeHours: yup.number().lessThan(10000).nullable(true).default(0),
	printDueDate: yup.date().nullable(true),
	paymentReceived: yup.boolean().nullable(false).default(0),
	contactDate: yup.date().nullable(true),
	replyDate: yup.date().nullable(true),
	quoteDate: yup.date().nullable(true),
	followUpDate: yup.date().nullable(true),
	notes: yup.string().max(65535).ensure().nullable(false),
	version: yup.number().integer().min(0).max(4294967295).nullable(false).default(1),
	updatedAt: yup.date().nullable(false),
	isFinished: yup.string().oneOf(['False','True']).nullable(false)
})

Programmatic

Returns a promise that resolves to a string containing the code snippet above.

const yupSql = require('yup-sql')

yupSql({
    host: 'localhost',
    user: 'root',
    password: 'abc123',
    schema: 'awesomedb',
    table: 'customer',
    camel: true
}).then(result => {
	typeof result // => 'string'
})

You may also pass in an optional connection property which must be a mysql connection instance.

Pull requests welcome.

License

WTFPL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.