Skip to content

joerivv/db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

db

A simple, local database tool.

  • One database = one table = one file.
  • XML storage, for bigger databases you can opt into XMLDB (an SQLite wrapper)
  • There is no schema. Fields (columns) are based on input data.
  • Import from CSV, TSV, JSON, XLSX, XML or plain lists
  • Export to XML, JSON, TXT, CSV, TSV, PHP, or a list of values
  • Retrieve data from the command line, from an HTTP server or through JavaScript scripts

Quick Start

Create a database named "coffee":

$ db coffee

Import data:

$ db coffee import beans.csv
$ db coffee import beans.json
$ db coffee import beans.xlsx
$ db coffee import -s "bean,caffeine\nRobusta,2.5%"
$ db coffee import -s "{\"bean\":\"Robusta\",\"caffeine\":\"2.5%\"}"

Get all records:

$ db coffee as xml
$ db coffee as json
$ db coffee as txt
$ db coffee as csv
$ db coffee as csv --tabs
$ db coffee as tsv
$ db coffee as php
$ db coffee as php --short
$ db coffee as list

Access through REST API

A built-in web server provides access through HTTP requests for use in local web apps.

$ db coffee serve
Serving coffee on http://localhost:7777
const coffee = "http://localhost:7777"

fetch(coffee)
    .then(result => result.json())
    .then(records => /* do your thing */)

Access through JavaScript API

You can access and manipulate the database with JavaScript:

$ db people run script.js

Read/write database

db.read()

for (let person of db.records) {
    person.fullName = person.firstName + " " + person.lastName
    delete person.firstName
    delete person.lastName
}

db.write()

Working with files

db.read()

let names = db.records.map(user => user.name).join("\n")

file("just-the-names.txt").write(names)

Working with folders

for (let item of folder("~/Downloads").items) {
    if (item.extension == "pkg") {
        item.trash()
    }
}

Running shell commands

let listing = shell("ls -la")

Running AppleScript

applescript('tell application "Finder" to activate')

About

A simple, local database tool.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages