67 lines
No EOL
1.9 KiB
Bash
67 lines
No EOL
1.9 KiB
Bash
#!/bin/sh
|
|
# Generates example dataset and does some stuff
|
|
|
|
|
|
if [ ! -d "example" ]; then
|
|
mkdir example
|
|
fi
|
|
|
|
cd example
|
|
|
|
set -x
|
|
|
|
# Create a personnel dataset with three people
|
|
# The name, ID, and state of residence are known for each person
|
|
mkdir people
|
|
touch ./people/Sandeep ./people/Sofia ./people/Wulfrum
|
|
ghee set -s name=Sandeep -s id=2 -s state=CA ./people/Sandeep
|
|
ghee set -s name=Sofia -s id=1 -s state=WA ./people/Sofia
|
|
ghee set -s name=Wulfrum -s id=0 -s state=CA ./people/Wulfrum
|
|
|
|
# Tell Ghee what key the data is indexed by
|
|
ghee init -k name ./people
|
|
|
|
# Index the dataset by ID
|
|
ghee idx -v -k id ./people ./people:id
|
|
|
|
# Index the dataset by state and ID, placing the index in the default path
|
|
ghee idx -v -k state -k id ./people
|
|
|
|
# Add more people to the table and its indices
|
|
ghee ins -v ./people < ../people.json
|
|
|
|
# Get all of ./people
|
|
ghee get -a ./people
|
|
|
|
# Get all of ./people without sorting in the walk of the folder hierarchy
|
|
ghee get -a --nosort ./people
|
|
|
|
# Get the name of everybody from California; include all subpaths (don't ignore indices)
|
|
ghee get -a -w state=CA -f name ./people
|
|
|
|
# Remove Sofia
|
|
ghee del -v ./people -w name=Sofia
|
|
# Equivalently: ghee del -v ./people Sofia
|
|
|
|
# Remove Lilly from the :id index and all related indices
|
|
ghee del -v ./people:id 3
|
|
# Equivalently: ghee del -v ./people -w id=3
|
|
# Equivalently: ghee del -v ./people Lilly
|
|
|
|
# Remove Wulfrum from the :state:id index and all related indices
|
|
ghee del -v ./people/:state:id CA 0
|
|
# Equivalently: ghee del -v ./people -w state=CA -w id=0
|
|
# Equivalently: ghee del -v ./people Wulfrum
|
|
|
|
# Get the name of everybody from California still remaining,
|
|
# taking advantage of the state index
|
|
# This will avoid traversing irrelevant portions of the index
|
|
ghee get -a -w state=CA -f name ./people/:state:id
|
|
|
|
# Create a table directly
|
|
ghee create -v ./direct -k blah
|
|
|
|
# Create people2 in one go using `create'
|
|
ghee create -v ./people2 -k id < ../people.json
|
|
|
|
cd .. |