Cindex, a csv indexer
Cindex is a easy to use csv indexer with a simple SQL-like query support.
Cindex is not intended for heavy database indexing but for simple in-memory querying. Use other databases interaction layer if you're using big chunks of csv files.
Usage
[]
= "*" # Use the latest version if possible
# Use "default-features = false" if you don't need rayon iteration enhancement.
use File;
use ;
let mut indexer = new;
// Add table without types
// Default types for every columns are "Text"
indexer.add_table_fast.expect;
// Add table with column types
indexer.add_table.expect;
// Add table from stdin
let stdin = stdin;
indexer.add_table_fast.expect;
// Indexing
// Create query object and print output to terminal
let query = from_str;
indexer.index.expect;
// Use raw query and yield output to a file
indexer.index_raw.expect;
// Use builder pattern to construct query and index a table
let query = empty
.columns
.predicate
.predicate;
let mut acc = Stringnew;
indexer.index
.expect;
// Always use unix newline for formatting
indexer.always_use_unix_newline;
Query syntax
Cindex's query syntax is similar to SQL but has some small differences.
/* Select everythig from given table*/
SELECT * FROM table1
/* Select everything from given table and order by column with descending
order*/
SELECT * FROM table1 ORDER BY col1 DESC
/* Same with previous commands but map header result */
SELECT * FROM table1 ORDER BY col1 DESC HMAP new_h,new_h2,new_h3
/* -> Previous query result header with underbar substituted with whitespaces
new h,new h2,new h3
<-- Content goes here -->
*/
/* Select given columns from table where column's value is equal to given
condition and also other column's value matches regex expression */
SELECT col1,col2 FROM table1 WHERE col1 = 10 AND col2 LIKE ^start
/* There is a flag syntax which changes query behaviour*/
SELECT * FROM table_name FLAG PHD SUP
/* In this case each flag does next operation
- PHD (PRINT-HEADER) : Print header in result output
- SUP (SUPPLEMENT) : Enable selection of non-existent column with empty values
*/
Supported WHERE operations are
>=
>
<=
<
=
!=
IN
BETWEEN
LIKE ( with regeular expression )
TODO
- DateTime csv type
- Multi where caluse support
- Join table