Skip to content

Commit bff37fb

Browse files
committed
Add Asciinema recording
1 parent 70bed26 commit bff37fb

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ The end result is pretty nice, as from host perspective the only tool required i
6060
install MySQL/PostgreSQL if all you want is to load the .sql dump and transform it to JSON.
6161
Just remove the temporary DBMS and sql2json containers when you're done and your system is clean as ever. :)
6262

63+
Demo
64+
====
65+
66+
[![asciicast](https://asciinema.org/a/722yo4odqo1sulztyaeaxz4k1.png)](https://asciinema.org/a/722yo4odqo1sulztyaeaxz4k1)
67+
68+
6369
Walkthroughs
6470
============
6571

misc/asciinema_script.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
PS1='\[\033[0;33m\]~/sql2json \$ \[\033[0m\]'
3+
4+
5+
# here's the .sql file we have that we would like to export as JSON
6+
cat example_dataset/Chinook_PostgreSql.sql.gz | gzip -d | head -30
7+
8+
# first we'll launch Postgres instance so we can import the data there
9+
docker run -d --name sql2json-dbserver -p 5432:5432 kiasaki/alpine-postgres:9.5
10+
11+
# then we'll create an empty database
12+
echo 'CREATE DATABASE chinook' | docker exec -i sql2json-dbserver psql -U postgres postgres
13+
14+
# now we'll import the data into it
15+
cat example_dataset/Chinook_PostgreSql.sql.gz | gzip -d | docker exec -i sql2json-dbserver psql -U postgres chinook > /dev/null
16+
17+
# let's find out the IP address of the database server
18+
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sql2json-dbserver
19+
20+
# create directory for the resulting JSON files
21+
mkdir sql2json_result
22+
23+
# and now export the database as JSON
24+
docker run --rm -it -v "$(pwd)/sql2json_result:/result" -e "DSN=postgres,,pgsql:dbname=chinook;host=172.17.0.2;port=5432" joonas/sql2json
25+
26+
# take a look at the resulting file structure
27+
tree sql2json_result/
28+
29+
# now you can work with the dataset from the commandline
30+
cat sql2json_result/data/Album.json.gz | gzip -d | jq '.[0]'
31+
32+
# even sort the whole table by "Title" column
33+
cat sql2json_result/data/Album.json.gz | gzip -d | jq '.[].Title' | sort | head -10
34+
35+
# destroy the database instance
36+
docker rm -f sql2json-dbserver
37+
38+
# thanks for watching!

0 commit comments

Comments
 (0)