# HG changeset patch # User František Kučera # Date 1572363623 -3600 # Node ID de1b49ba06f1d7a9678394ab9f089ea6c9a5a7c1 # Parent ae17db13569c98637dcd41f2b3dfe993cf9f1270 examples: SELECTing from SQLite databases diff -r ae17db13569c -r de1b49ba06f1 relpipe-data/examples-in-sql-selecting-existing-database.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-in-sql-selecting-existing-database.xml Tue Oct 29 16:40:23 2019 +0100 @@ -0,0 +1,99 @@ + + + SELECTing from SQLite databases + read from an existing SQLite file or update it + 03300 + + + +

+ Both the relpipe-tr-sql and relpipe-in-sql + support the option --file and can store data in a file instead of just in-memory. + Primary purpose of this option is to offload to HDD and be able to process more data whithout consuming too much RAM. + So such file is usually a temporary one and is deleted immediately after the transformation. + But we can also direct it to an existing file and append new relations to it. + Or we can create a new file and do not delete it – using the --file-keep true option. +

+ +

+ Thus we can use the relpipe-in-sql as a database client to access existing SQLite files and SELECT from them (and then convert the results to any supported format). + An we can use the relpipe-tr-sql as an output filter which converts relational data to a SQLite file that can be queried later. +

+ +

+ SQLite is a popular format used by many applications to store structured data. + Version control systems (VCS) like Monotone or Fossil + use it as a repository format and put whole history, data and metadata into it. +

+ +

+ So if we clone a Fossil repository (the SQLite one in this case): +

+ + + +

+ We can then query it using tools: +

+ + + +

and get some aggregated statistics:

+ + + +

+ Accessing internal data structures of another application might be bit tricky (if the application does not guarantee it as a stable API), + but it can be used for ad-hoc digging and even in regular use, there are chances that such „API“ will not break for a reasonable period of time. +

+ +

+ However, best results can be achieved, if the database scheme is under our control or defined as a stable API by someone else. +

+ +

+ All relations or their subset can be dumped even without writing any SELECTs: just use --copy '.*' + or e.g. --copy 'tickets|tag|evet' or --copy-renamed 'tickets|tag|evet' 'copy_of_$0' and get exported some relations under modified names (using regular expressions). + Such export can be converted e.g. to Recfile or XML format using corresponding output filter. +

+ +
+ +