Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package

go-libraryofcongress-database

Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package.

Important

This is work in progress and not documented properly yet. The code will continue to move around in the short-term. Everything you see here is still in the "proof-of-concept" phase. It should work but may still have bugs and probably lacks features.

Motivation

The first goal is to have a simple, bare-bones HTTP server for querying data in the CSV files produced by the sfomuseum/go-libraryofcongress package.

The second goal is to be able to build, compile and deploy the web application and all its data (as SQLite databases) as a self-contained container image to a low-cost service like AWS App Runner.

A third goal is to have a generic database interface such that the same code can be used with a variety of databases. As written the server tool only has a single database "driver" for querying SQLite databases but there are tools for indexing data in both Elasticsearch and SQLite databases.

Data

A sample SQLite database for Library of Congress subject headings is currently included with this package in the data folder. Some notes:

  • This database is stored using git-lfs.
  • This databases was created using the to-sqlite tool described below.
  • It is not clear whether an equivalent (or combined) database for Library of Congress named authorities will ever be included because it is very large.
  • Eventually bundled data may be removed entirely.
  • As written the code only handles a subset of all the possible (CSV) columns produced by the sfomuseum/go-libraryofcongress tools. Specifically: id and label. A third source column is appended to the databases to distinguish between Library of Congress subject heading and name authority file records.

Databases

To be written

Tools

server

The server tool is a simple web interface providing humans and robots, both, the ability to query a database.

$> ./bin/server -h
Usage of ./bin/server:
  -database-uri string
    	A valid sfomuseum/go-libraryofcongress-database URI. (default "sql://sqlite3?dsn=data/lcsh.db")
  -per-page int
    	The number of results to return per page (default 20)
  -server-uri string
    	A valid aaronland/go-http-server URI. (default "http://localhost:8080")

To start the server you might do something like this:

$> ./bin/server -database-uri 'sql://sqlite3?dsn=data/lcsh.db' -per-page 10
2021/10/18 13:11:24 Listening on http://localhost:8080

And then if you opened http://localhost:8080/?q=River&page=2 in a web browser you'd see this:

There is also an API endpoint for querying the data as JSON:

$> curl -s 'http://localhost:8080/api/query?q=SQL' | jq
{
  "results": [
    {
      "id": "sh96008008",
      "label": "PL/SQL (Computer program language)",
      "source": "lcsh"
    },
    {
      "id": "sh86006628",
      "label": "SQL (Computer program language)",
      "source": "lcsh"
    },
    {
      "id": "sh90004874",
      "label": "SQL*PLUS (Computer program language)",
      "source": "lcsh"
    },
    {
      "id": "sh87001812",
      "label": "SQL/ORACLE (Computer program language)",
      "source": "lcsh"
    }
  ],
  "pagination": {
    "total": 4,
    "per_page": 10,
    "page": 1,
    "pages": 1,
    "next_page": 0,
    "previous_page": 0,
    "pages_range": []
  }
}

Notes

  • The server tool only supports SQLite databases as of this writing.
  • The server tool does not yet have the ability to define custom prefixes for URLs. For the time being it is assumed that everything is served from a root / URL.

to-elasticsearch

The to-elasticsearch tool will index CSV data produced by the tools in sfomuseum/go-libraryofcongress in an Elasticsearch index.

$> ./bin/to-elasticsearch -h /Users/asc/sfomuseum/go-libraryofcongress-database                                                    
Usage of ./bin/to-elasticsearch:
  -elasticsearch-endpoint string
    	The Elasticsearch endpoint where data should be indexed. (default "http://localhost:9200")
  -elasticsearch-index string
    	The Elasticsearch index where data should be stored. (default "libraryofcongress")
  -lcnaf-data string
    	The path to your LCNAF CSV data.
  -lcsh-data string
    	The path to your LCSH CSV data.
  -workers int
    	The number of concurrent workers to use when indexing data. (default 10)

to-sqlite

The to-sqlite tool will index CSV data produced by the tools in sfomuseum/go-libraryofcongress in a SQLite database.

$> ./bin/to-sqlite -h
Usage of ./bin/to-sqlite:
  -dsn string
    	The SQLite DSN for the database you want to create. (default "libraryofcongress.db")
  -lcnaf-data string
    	The path to your LCNAF CSV data.
  -lcsh-data string
    	The path to your LCSH CSV data.

Docker

Yes, there is a Dockerfile for the server tool. The simplest way to get started is to run the docker target in this package's Makefile:

$> make docker

And then to start the server:

$> docker run -it -p 8080:8080 \
	-e LIBRARYOFCONGRESS_DATABASE_URI='sql://sqlite3?dsn=/usr/local/data/lcsh.db' \
	-e LIBRARYOFCONGRESS_SERVER_URI='http://0.0.0.0:8080' \
	libraryofcongress-server

And then visit http://localhost:8080 in a web browser.

Notes

  • As written the Dockerfile will copy all files ending in .db in the data folder in to the container's /usr/local/data folder.

See also

Owner
San Francisco International Airport Museum
San Francisco International Airport Museum
Similar Resources

CRUD API example is written in Go using net/http package and MySQL database.

CRUD API example is written in Go using net/http package and MySQL database.

GoCrudBook CRUD API example is written in Go using net/http package and MySQL database. Requirements Go MySQL Code Editor Project Structure GoCrudBook

Dec 10, 2022

A simple Golang-based application that queries a PostgreSQL database

Qwik-E-Mart Demo App A simple Golang-based application that queries a PostgreSQL database named qwikemart to read and return customer data stored in t

Nov 6, 2021

Go-get-it - Simple database query script for UNIX-terminal usage

go-get-it Simple database query script for UNIX-terminal usage Supports MongoDB Quick start Commands: Usage of ggi: -c string MongoDB collectio

Nov 1, 2022

Querycrate - A simple library that loads and keeps SQL queries from files

QueryCrate A simple library for loading & getting string queries from files. How

Feb 15, 2022

Schemable - Schemable provides basic struct mapping against a database, using the squirrel package

Schemable Schemable provides basic struct mapping against a database, using the

Oct 17, 2022

gdb-drivers: Database drivers for package gdb.

gdb-drivers Database drivers for package gdb. Installation Let's take pgsql for example. go get -u github.com/gogf/gf/gdb-drivers Choose and import t

Jan 21, 2022

A go package to add support for data at rest encryption if you are using the database/sql.

go-lockset A go package to add support for data at rest encryption if you are using the database/sql to access your database. Installation In your Gol

Jan 30, 2022

Package dbi implements an experimental database/sql wrapper.

dbi Package dbi implements a database/sql wrapper. This is an EXPERIMENTAL package used for experimenting. Installation The recommended way to install

Feb 8, 2022

Google Cloud Spanner driver for Go's database/sql package.

go-sql-spanner Google Cloud Spanner driver for Go's database/sql package. This support is currently in the Preview release status. import _ "github.co

Dec 11, 2022
Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).

?? Dumpling Dumpling is a tool and a Go library for creating SQL dump from a MySQL-compatible database. It is intended to replace mysqldump and mydump

Nov 9, 2022
Use SQL to data from CSV files. Open source CLI. No DB required.
Use SQL to data from CSV files. Open source CLI. No DB required.

CSV Plugin for Steampipe Use SQL to query data from CSV files. Get started → Documentation: Table definitions & examples Community: Slack Channel Get

Nov 10, 2022
Get data from .csv files use SQL-like queries.

csvql Get data from .csv files use SQL-like queries. Задание Необходимо написать консольную программу, которая по заданному клиентом запросу осуществл

Dec 7, 2021
[mirror] the database client and tools for the Go vulnerability database

The Go Vulnerability Database golang.org/x/vulndb This repository is a prototype of the Go Vulnerability Database. Read the Draft Design. Neither the

Dec 29, 2022
Database - Example project of database realization using drivers and models

database Golang based database realization Description Example project of databa

Feb 10, 2022
CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. Can output to various formats.
CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. Can output to various formats.

trdsql CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. It is a tool like q, textql and others. The difference from these tools is t

Jan 1, 2023
Run SQL queries against JSON, CSV, Excel, Parquet, and more.

Run SQL queries against JSON, CSV, Excel, Parquet, and more This is a CLI companion to DataStation (a GUI) for running SQL queries against data files.

Dec 31, 2022
Single binary CLI for generating structured JSON, CSV, Excel, etc.

fakegen: Single binary CLI for generating a random schema of M columns to populate N rows of JSON, CSV, Excel, etc. This program generates a random sc

Dec 26, 2022
🏋️ dbbench is a simple database benchmarking tool which supports several databases and own scripts

dbbench Table of Contents Description Example Installation Supported Databases Usage Custom Scripts Troubeshooting Development Acknowledgements Descri

Dec 30, 2022