Skip to content

Commit

Permalink
Add support for dumping to file
Browse files Browse the repository at this point in the history
* change tables from TEMP to no-temp so they are persisted during the
  .dump command
* add documentation in README about dumping to disk
  • Loading branch information
fzakaria committed Sep 29, 2023
1 parent c3c4029 commit 4f2c462
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ For instance, to have _sqelf_ emit JSON you can do the following:
{ "path": "\/usr\/bin\/ruby", "name": ".note.gnu.property"},
```

`sqlelf` will store the data from the ELF file into in-memory SQLite database. This allows you to run multiple queries against the same file(s) without having to reparse them and is much more efficient than iterating the ELF structures. This comes at the cost of startup time.

You can however _dump_ the sqlite database to a file on disk and then load it back up later. This is useful if you want to run many queries against the same file(s) and don't want to pay the startup cost each time.

```console
sqlelf /nix/store/gjr9ylm023rl9di484g1wxcd1jp84xxv-nix-2.8.1/bin/nix \
--sql ".dump /tmp/nix.sqlite"
file /tmp/nix-backup.sqlite
/tmp/nix-backup.sqlite: SQLite 3.x database, last written using SQLite version 3043001, writer version 2,
read version 2, file counter 3, database pages 14069, cookie 0x2, schema 4, UTF-8, version-valid-for 3
```

### Queries

<details>
Expand Down
2 changes: 1 addition & 1 deletion sqlelf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def register_generator(

if generator_flag in cache_flags:
connection.execute(
f"""CREATE TEMP TABLE {original_table_name}
f"""CREATE TABLE {original_table_name}
AS SELECT * FROM {table_name};"""
)

Expand Down

0 comments on commit 4f2c462

Please sign in to comment.