forked from nao1215/filesql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
86 lines (86 loc) · 2.83 KB
/
doc.go
File metadata and controls
86 lines (86 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Package filesql provides a file-based SQL driver implementation that enables
// querying CSV, TSV, LTSV, Parquet, and Excel (XLSX) files using SQLite3 SQL syntax.
//
// filesql allows you to treat structured text files as SQL databases without
// any data import or transformation steps. It uses SQLite3 as an in-memory
// database engine, providing full SQL capabilities including JOINs, aggregations,
// window functions, and CTEs.
//
// # Features
//
// - Query CSV, TSV, LTSV, Parquet, and Excel (XLSX) files using standard SQL
// - Automatic handling of compressed files (gzip, bzip2, xz, zstandard)
// - Support for multiple input sources (files, directories, io.Reader, embed.FS)
// - Efficient streaming for large files with configurable chunk sizes
// - Cross-platform compatibility (Linux, macOS, Windows)
// - Optional auto-save functionality to persist changes
//
// # Basic Usage
//
// The simplest way to use filesql is with the Open or OpenContext functions:
//
// db, err := filesql.Open("data.csv")
// if err != nil {
// log.Fatal(err)
// }
// defer db.Close()
//
// rows, err := db.Query("SELECT * FROM data WHERE age > 25")
// if err != nil {
// log.Fatal(err)
// }
// defer rows.Close()
//
// # Advanced Usage
//
// For more complex scenarios, use the Builder pattern:
//
// builder := filesql.NewBuilder().
// AddPath("users.csv").
// AddPath("orders.tsv").
// EnableAutoSave("./output")
//
// validatedBuilder, err := builder.Build(ctx)
// if err != nil {
// log.Fatal(err)
// }
//
// db, err := validatedBuilder.Open(ctx)
// if err != nil {
// log.Fatal(err)
// }
// defer db.Close()
//
// # Table Naming
//
// Table names are automatically derived from file paths:
// - "users.csv" becomes table "users"
// - "data.tsv.gz" becomes table "data"
// - "/path/to/logs.ltsv" becomes table "logs"
// - "sales.xlsx" with multiple sheets becomes tables "sales_Sheet1", "sales_Sheet2", etc.
//
// # Data Modifications
//
// INSERT, UPDATE, and DELETE operations affect only the in-memory database.
// Original files remain unchanged unless auto-save is enabled. To persist
// changes manually, use the DumpDatabase function.
//
// # SQL Syntax
//
// Since filesql uses SQLite3 as its underlying engine, all SQL syntax follows
// SQLite3's SQL dialect. This includes support for:
// - Common Table Expressions (CTEs)
// - Window functions
// - JSON functions
// - Date and time functions
// - And all other SQLite3 features
//
// # Column Name Handling
//
// Column names are handled with case-sensitive comparison for duplicate detection,
// maintaining backward compatibility. Headers with identical names after trimming
// whitespace (regardless of case differences) are considered duplicates and will
// result in an error.
//
// For complete SQL syntax documentation, see: https://www.sqlite.org/lang.html
package filesql