Single configuration of authorisation details.
--- /dev/null
+package Shiar_Sheet::DB;
+
+use 5.014;
+use warnings;
+use DBIx::Simple;
+
+our $VERSION = '1.00';
+
+my @dbinfo = (
+ 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
+) or die "database not configured\n";
+our $db;
+
+sub connect {
+ return $db if $db and $db->dbh->ping;
+ $db = DBIx::Simple->new(@dbinfo[0..2], {
+ RaiseError => 1,
+ pg_enable_utf8 => 1,
+ });
+ $db->abstract->{array_datatypes}++;
+ return $db;
+}
+
+1;
-#!/bin/sh
-echo 'use utf8;'
-psql sheet -XAt -c "
- SELECT json_object_agg(coalesce(id::text, ''), forms) FROM _cat_words
-" | sed 's/ : / => /g'
+#!/usr/bin/env perl
+use 5.014;
+use warnings;
+
+BEGIN { push @INC, '.' }
+use Shiar_Sheet::DB;
+use open ':std' => ':utf8';
+my $db = Shiar_Sheet::DB->connect;
+
+say 'use utf8;';
+
+use Data::Dump 'pp';
+say pp { $db->select(_cat_words => "coalesce(id::text, ''), forms")->map };
use List::Util qw( pairs pairkeys );
my $db = eval {
- my @dbinfo = (
- 'DBI:Pg:dbname=sheet;host=localhost', 'sheetadmin', 'fairuse',
- ) or die "database not configured\n";
- require DBIx::Simple;
- DBIx::Simple->new(@dbinfo[0..2], {
- RaiseError => 1,
- pg_enable_utf8 => 1,
- });
+ require Shiar_Sheet::DB;
+ Shiar_Sheet::DB->connect;
} or Abort('Database error', 501, $@);
-$db->abstract->{array_datatypes}++;
my $user = eval {
if (defined $post{username}) {