Giter VIP home page Giter VIP logo

dddl's Introduction

dddl

codecov

dddl generates test Data from DDL (i.e. create table statements).
How data is generated depends on column types and options but the general idea is simple.
Generator adds 1 to previous data row by row so each column would have sequentially incremented number.
Given that we have the following statement,

 create table a (
   c1 char(5),
   c2 integer,
   c3 float,
   c4 binary(8)
 );

then we would get the following.

   c1      c2  c3    c4
L1 "a0001","1","0.1","b0000001"
L2 "a0002","2","0.2","b0000002"
L3 "a0003","3","0.3","b0000003"
L4 "a0004","4","0.4","b0000004"

This library is not yet stable. Any features or APIs are subject to change even if it's a minor version update.

Getting started

Installation

npm install dddl

Simple usage

import { parseAndGenerate } from 'dddl';
const sql = `
create table A (
    col1 char(3)
);
`;
async function main() {
  try {
      const [rows, errors] = await parseAndGenerate(sql);
      // rows -> generated data
      console.log(rows);
      // errors -> data validation errors
      console.log(errors);
  } catch(error) {
      // error -> parse error or data generation error
      console.log(error);
  }
}
main();

Working demo

Here

Options

See API reference

Supported types

See API reference

Data validation

Currently followings are supported.

  • PRIMARY KEY constraint
  • UNIQUE KEY constraint
  • NOT NULL constraint

SQL parser

SQL syntax quite depends on DBMS products, so the create statement you have may or may not be valid for this library.
However this library basically comforms with the ANSI standards since the parser part of this library has been translated and ported from the Rust project named sqlparser-rs, which aims to comform with the standards, so hopefully the core part of your create statement (i.e. column definition) is valid for this library.

Lisence

Apache License 2.0

dddl's People

Contributors

kena0ki avatar

Watchers

 avatar  avatar

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.