npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dddl

v0.2.1

Published

dddl generates test Data from DDL

Downloads

6

Readme

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 '../dist/index.js';
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