-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): Change storage from Parquet to DuckDB
Signed-off-by: Arnau Siches <[email protected]>
- Loading branch information
Showing
7 changed files
with
115 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
data/config.nuon | ||
data/*/*.parquet | ||
.dial.nu | ||
data/dial.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use error.nu * | ||
use duckdb.nu | ||
|
||
def "db run" [sql: string] { | ||
let location = try-env DIAL_DB | ||
|
||
duckdb run $sql $location | ||
} | ||
|
||
|
||
# Initialises a new storage at the location indicated by the `DIAL_DB`. | ||
export def --env init [] { | ||
let location = if ($env.DIAL_DB? | is-empty) { "data/dial.db" } else { $env.DIAL_DB? } | ||
|
||
if ($location | path exists) { return } | ||
|
||
# TODO: Assumes context. | ||
db run (open dial/schema.sql) | ||
} | ||
|
||
def tables [] { | ||
let location = if ($env.DIAL_DB? | is-empty) { "data/dial.db" } else { $env.DIAL_DB? } | ||
|
||
duckdb run "select table_name from information_schema.tables where table_schema = 'main' and table_type = 'BASE TABLE';" $location | ||
| get table_name | ||
} | ||
|
||
# Attempts to save the given data into the Dial storage. | ||
export def save [table_name: string@"tables"] { | ||
let location = if ($env.DIAL_DB? | is-empty) { "data/dial.db" } else { $env.DIAL_DB? } | ||
|
||
if not ($location | path exists) { | ||
fail $"The database in ($location) does not exist. Please run `dial storage init`" | ||
} | ||
|
||
$in | ||
| duckdb upsert $table_name $location | ||
} | ||
|
||
export def query [sql: string] { | ||
let location = if ($env.DIAL_DB? | is-empty) { "data/dial.db" } else { $env.DIAL_DB? } | ||
|
||
if not ($location | path exists) { | ||
fail $"The database in ($location) does not exist. Please run `dial storage init`" | ||
} | ||
|
||
duckdb run $sql $location | ||
} |