@chork/simple-db-repository

Deal with sqlite and postgresql tables using schemas you define in JSON.

Usage no npm install needed!

<script type="module">
  import chorkSimpleDbRepository from 'https://cdn.skypack.dev/@chork/simple-db-repository';
</script>

README

Simple DB Repository

Deal with sqlite and postgresql tables using schemas you define in JSON.

Introduction

Here are the features for this node module.

  • Create
  • Read
  • Update
  • Delete
  • Create Tables
  • Drop Tables

Schema

Everything with sqlite repository relies on a schema declaration. Here is the specification.

Simple Schema

const personTable = {
    name: "person",
    version: "1.0.0",
    label: "People",
    description: "A place to store people.",
    columns: [
        {
            type: "INTEGER",
            name: "id",
            label: "Identity"
        },
        {
            type: "TEXT",
            name: "firstName",
            label: "First Name"
        },
        {
            type: "TEXT",
            name: "lastName",
            label: "Last Name"
        }
    ],
    primaryKeys: ["id"]
};

Foreign Keys

const = {
    name: "address",
    label: "Address",
    description: "Address Table",
    version: "1.0.0",
    columns: [
        {
            type: "INTEGER",
            name: "id",
            label:"Identifier"
        },
        {
            type: "TEXT",
            name: "address",
            label: "Address"
        },
        {
            type: "TEXT",
            name: "city",
            label: "City"
        },
        {
            type: "INTEGER",
            name: "state",
            label: "State"
        },
        {
            type: "INTEGER",
            name: "zipCode",
            label: "Zip Code"
        },
        {
            type: "INTEGER",
            name: "personId",
            label: "Person Id",
            isRequired: true
        }
    ],
    primaryKeys:["id"],
    foreignKeys: {
            personId: {
                label: "Person",
                source: {
                    name: "person",
                    version: "1.0.0",
                    label: "Addresses",
                    column: "id"
                }
            }
    }
};