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

dbs-sync

v0.0.2

Published

Database Synchronizer

Downloads

3

Readme

🔃 DbS

Introduction

DbS, Database Synchronizer, is a PoC about the idea of creating a tool that allows to facilitate the synchronization of data models. It's operation consists of comparing two JSONs representing the data models and, based on the differences between them, generate SQL scripts that perform the synchronization. Some important details:

  • current only supports PL/SQL syntax
  • currently only supports CREATE and DROP object commands
  • currently the objects that are supported are:
    • function
    • grant
    • package
    • procedure
    • sequence
    • table
    • trigger
    • view

Installation

⚠️ Prerequisite:

⚠️ ATTENTION:
🚦 This is an experimental tool and is under construction 🚧, so there are limitations and the possibility of errors

You can install DbS using npm:

$ npm install dbs-sync

or using yarn:

$ yarn add dbs-sync

Models

Each object has an expected entity model, which contains important information for script generation.
Below are the expected models:

export interface Grant {
  schemaName: string;
  objectName: string;
  type: string;
  grantor: string;
  grantee: string;
  privilege: string;
  script: string;
}

export interface Parameter {
  name: string;
  type: string;
  in: boolean;
  out: boolean;
}

export interface Function {
  name: string;
  schemaName: string;
  replace: boolean;
  returnType: string;
  is: boolean;
  script: string;
  body: string;
  declarations: string[];
  parameters: Parameter[];
  grants: Grant[];
}

export interface Package {
  name: string;
  schemaName: string;
  replace: boolean;
  is: boolean;
  script: string;
  declarations: string;
  grants: Grant[];
}

export interface Column {
  name: string;
  type: string;
  nullable: boolean;
  comment: string;
  tableName: string;
  schemaName: string;
}

export interface SelectColumn {
  name: string;
  tableName: string;
  joinTable: string;
  joinType: 'JOIN' | 'LEFT JOIN' | 'RIGHT JOIN' | 'FULL JOIN';
  joinCondition: string;
}

export interface View {
  name: string;
  schemaName: string;
  script: string;
  columns: SelectColumn[];
  conditions: string;
  grants: Grant[];
}

export interface Trigger {
  name: string;
  tableName: string;
  schemaName: string;
  replace: string;
  before: boolean;
  event: string;
  forEachRow: boolean;
  enabled: boolean;
  condition: string;
  declarations: string[];
  executionBody: string[];
  exceptionBody: string[];
  script: string;
}

export interface Procedure {
  name: string;
  schemaName: string;
  replace: boolean;
  script: string;
  is: boolean;
  declarations: string[];
  executionBody: string[];
  exceptionBody: string[];
  parameters: Parameter[];
  grants: Grant[];
}

export interface Sequence {
  name: string;
  schemaName: string;
  incrementBy: number;
  cacheSize: number;
  startWith: number;
  script: string;
  minValue: number;
  maxValue: number;
  grants: Grant[];
}

export interface Constraint {
  schemaName: string;
  tableName: string;
  constraintName: string;
  relatedColumns: string;
  constraintType: string;
  conditions: string[];
  references: string;
  invalid: string;
  relatedView: string;
  status: string;
  validated: string;
}

export interface Index {
  indexName: string;
  schemaName: string;
  tableName: string;
  columns: string;
  indexType: string;
  uniqueness: boolean;
}

export interface Table {
  schemaName: string;
  name: string;
  comment: string;
  script: string;
  columns: Column[];
  indexes: Index[];
  constraints: Constraint[];
  grants: Grant[];
}

Usage

import sqlGeneration from 'dbs-sync';

const sourceModel = [
  {
    "schemaName": "",
    "name": "author",
    "comment": "",
    "script": "CREATE TABLE author(\n  id NUMBER NOT NULL,\n  author_name VARCHAR2(150) NOT NULL,\n  birth_date DATE\n);",
    "columns": [
      {
        "name": "id",
        "type": "NUMBER",
        "nullable": false,
        "comment": "",
        "tableName": "author"
      },
      {
        "name": "author_name",
        "type": "VARCHAR2(150)",
        "nullable": false,
        "comment": "",
        "tableName": "author"
      },
      {
        "name": "birth_date",
        "type": "DATE",
        "nullable": true,
        "comment": "",
        "tableName": "author"
      }
    ],
    "indexes": [],
    "grants": [
      {
        "schemaName": "",
        "objectName": "author",
        "type": "TABLE",
        "grantor": "",
        "grantee": "public",
        "privilege": "SELECT",
        "script": "GRANT SELECT ON author TO public;"
      }
    ]
  }
];

const targetModel = [];

const result = sqlGeneration(
  "Tables", // the type of object that will be synchronized
  "plsql", // the syntax of the database in which you want the scripts
  sourceModel, // the data source model
  targetModel // the target model of the changes
);
console.log(result);
/*
CREATE TABLE author(
  id NUMBER NOT NULL,
  author_name VARCHAR2(150) NOT NULL,
  birth_date DATE
);

GRANT
SELECT
  ON author TO PUBLIC;
*/