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

dbmodel

v5.5.7-alpha.60

Published

Deploy, load or build script from model of SQL database

Downloads

1,079

Readme

dbmodel

Deploy, load or build script from model of SQL database. Can be used as command-line tool. Uses DbGate tooling and plugins for connecting many different databases.

If you want to use this tool from JavaScript interface, please use dbgate-api package.

Model is stored as a collection of files:

  • tables - stored as YAML files
    • columns
    • indexes
    • primary keys
    • foreign keys
  • views - stored as SQL file with extension .view.sql
  • stored procedures - stored as SQL file with extension .proc.sql
  • functions - stored as SQL file with extension .func.sql

Installation - as global tool

npm install --global dbmodel

Installation - as regular package

npm install --save dbmodel

Available commands

  • load - loads structure of database, saves it to local directory (called project). Also can download data of enlisted tables (use --load-data-condition options)
  • deploy - deploys structure from local directory (project) to database. Deploy does not perform any actions leading to data loss, these changes must be made manually.
    • creates not existing tables
    • creates not existing columns of existing tables
    • checks column NULL/NOT NULL flag, alters colums
    • checks tables, which are in database, but not in project, list of these tables are reported
    • checks columns, which are in database, but not in project, list of these columns are reported
    • checks indexes and its definitions, indexes are created or recreated, if neccessary (but not deleted)
    • checks and creates foreign keys
    • checks, creates new or changes existing views, stored procedures and functions
    • updates and creates static data (included in table yaml files)
  • build - builds script from project folder. This operation is complete offline, no database connection is needed. Built script makes subset of deploy command. It can be executed on empty database, but also it can convert existing database to current structure (but only using operations below).
    • creates not existing tables
    • creates not existing columns of existing tables
    • creates not existing indexes (checked only by name)
    • creates not existing foreign keys
    • creates new or changes existing views, stored procedures and functions
    • updates and creates static data (included in table yaml files)

Command line interface

# load from existing database
dbmodel load -s localhost -u USERNAME -p PASSWORD -d DATABASE -e mssql@dbgate-plugin-mssql OUTPUT_FOLDER

# deploy project to database
dbmodel deploy -s localhost -u USERNAME -p PASSWORD -d DATABASE -e mssql@dbgate-plugin-mssql PROJECT_FOLDER

# build SQL script from project
dbmodel build -e mssql@dbgate-plugin-mssql PROJECT_FOLDER OUTPUT_FILE.sql

Parameter -e (or --engine) specifies database dialect and connection driver to be used Supported databases:

  • MySQL - -e mysql@dbgate-plugin-mysql
  • MS SQL Server - -e mssql@dbgate-plugin-mssql
  • PostgreSQL - -e postgres@dbgate-plugin-postgres
  • SQLite - -e sqlite@dbgate-plugin-sqlite
  • Oracle - -e oracle@dbgate-plugin-oracle
  • MariaDB - -e mariadb@dbgate-plugin-mysql
  • CockroachDB - -e cockroach@dbgate-plugin-postgres
  • Amazon Redshift - -e redshift@dbgate-plugin-postgres

Table yaml file documentation

name: Album # table name
columns:
  - name: AlbumId # column name
    type: int # data type. is used directly in target SQL engine 
    autoIncrement: true # column is autoincrement
    notNull: true # column is not nullable (default: is nullable)
  - name: Title
    type: nvarchar
    length: 160 # maximum character length
    notNull: true
  - name: ArtistId
    type: int
    references: Artist # name of table. Is used for creating foreign key
  - name: isDeleted
    type: bit
    notNull: true
    default: 0 # default value
primaryKey:
  - AlbumId # list of primary key column names
indexes:
  - name: UQ_AlbumTitleArtistId # index name
    unique: true # whether index is unique. default=false
    columns: # list of index columns
      - Title
      - ArtistId
    filter: isDeleted=0 # if defined, filtered index (with WHERE condition) is created
    continueOnError: true # if true and there was error in creating this index, continue (suitable for lately added unique indexes)
data: # static data (only for list tables)
  - AlbumId: -1 # values for all columns, which should be filled
    Title: Predefined static album