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

zeryab-db

v1.3.7

Published

make sql file from json, yaml or xml file scheme.

Downloads

24

Readme

Zeryab DataBase

  • This is a README for a npm package that allows developers to create SQL files from JSON, YAML, or XML files. The package takes in a tables.json file that contains information about the database tables and columns. An example of the tables.json file is provided in the README, with tables such as "users" and "reactions" and their respective columns.

  • The package also takes in a relations.js file that contains information about foreign keys and relationships between tables. The relations.js file has a table key and a foreignKeys array that specifies which columns reference other tables. An example of the relations.js file is provided in the README, with the foreign keys between the "users_reactions" table and the "users" and "reactions" tables.

  • From these input files, the package generates SQL files for each table with its respective columns and foreign key constraints. An example of the generated SQL files is provided in the README, with files such as "users.sql", "reactions.sql", and "users_reactions_fk.sql".

  • Overall, this package simplifies the process of generating SQL files from JSON, YAML, or XML files, and provides a straightforward solution for developers to create and manage their database schemas.

SQL File Generator

  • This package helps developers create SQL files from JSON, YAML or XML files.

Installation

  • To install, run:
npm install zeryab-db

Usage

  • The package exposes a generateSqlFiles function that takes in two arguments:
const { SQLConfig, SQLGenerator } = require('zeryab-db');

const $SQLConfig = new SQLConfig('./.config/tables.json', './.config/relations.json');
const $SQLGenerator = new SQLGenerator();
const $sqlFiles = $SQLGenerator.generate( $SQLConfig, './tables/' );

console.table($sqlFiles); // will log the names of the generated files

Examples

  • Assuming we have a tables.json file with the following content:
[
  {
    "name": "users",
    "columns": [
      { "name": "userId", "type": "int(11) unsigned", "primaryKey": true },
      { "name": "userName", "type": "varchar(255)" }
    ]
  },
  {
    "name": "reactions",
    "columns": [
      { "name": "reactionId", "type": "int(11) unsigned", "primaryKey": true },
      { "name": "reactionName", "type": "varchar(255)" }
    ]
  },
  {
    "name": "users_reactions",
    "columns": [
      { "name": "userReactionId", "type": "int(11) unsigned", "primaryKey": true },
      { "name": "userId", "type": "int(11) unsigned" },
      { "name": "reactionId", "type": "int(11) unsigned" }
    ]
  }
]
  • And a relations.js file with the following content:
[
  {
    "table": "users_reactions",
    "keys": [
      {
        "table": "users",
        "column": "userId"
      },
      {
        "table": "reactions",
        "column": "reactionId"
      }
    ]
  }
]
  • The package will generate the following SQL files:

  • users.sql:

CREATE TABLE `users` (
  `userId` int(11) unsigned PRIMARY KEY,
  `userName` varchar(255)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  • reactions.sql:
CREATE TABLE `reactions` (
  `reactionId` int(11) unsigned PRIMARY KEY,
  `reactionName` varchar(255)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  • users_reactions.sql:
CREATE TABLE `users_reactions` (
  `userReactionId` int(11) unsigned PRIMARY KEY,
  `userId` int(11) unsigned,
  `reactionId` int(11) unsigned
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  • users_reactions_fk.sql:
ALTER TABLE `users_reactions`
  ADD CONSTRAINT `fk_users_reactions_users` FOREIGN KEY (`userId`) REFERENCES `users` (`userId`),
  ADD CONSTRAINT `fk_users_reactions_reactions` FOREIGN KEY (`reactionId`) REFERENCES `reactions` (`reactionId`);

Happy Coding 👩‍💻👨‍💻