#!/bin/bash
# README for nl_pegasus_load examples
#
# These examples test the nl_pegasus_load command.
#
# To run:
#
# ./README sqlite|mysql
#
dbfile=test.sqlite
dbname=f00b4r
if test "x$1" = x -o "x$1" = "x-h"
then
    printf "usage: $0 sqlite|mysql\n"
    exit 1
fi
if test $1 = sqlite
then
    url="sqlite://$dbfile"
    args=""
    rm -f $dbfile
elif test $1 = mysql
then
    url="mysql://localhost"
    args="-D $dbname"
    mysql -e "drop database $dbname"
    mysql -e "create database $dbname"
fi

cmd="nl_pegasus_load -v -C -d -u $url $args ."
printf "Running: $cmd\n"
$cmd

echo done
# If you have sqlite3, you can look at the database
if test $1 = sqlite; then
  printf "Events: "
  sqlite3 $dbfile "select count(*) from event"
  printf "First kickstart record:\n"
  sqlite3 -column -header $dbfile "select 'time' as 'name', time  as 'value' from event e where e.name = 'pegasus.invocation' limit 1"
  sqlite3 -column $dbfile "select a.name, a.value from event e join attr a on e.id = a.e_id where e.name = 'pegasus.invocation' limit 6"
  sqlite3 -column $dbfile "select i.name, i.value from event e join ident i on e.id = i.e_id where e.name = 'pegasus.invocation' limit 3"
fi
#
# Note that this file can be 
# run directly, e.g.
# . README

