-
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.
Added build scripts to test sqlite as an alternative to postgres, but…
… turns out postgres is a lot faster
- Loading branch information
1 parent
adac17f
commit 2ae0c04
Showing
3 changed files
with
151 additions
and
85 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
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,34 @@ | ||
import { createWriteStream, readFileSync } from "node:fs"; | ||
|
||
// expect first argument to be attributes.json, second to be desired | ||
// output path for sql statements | ||
const attributesPath = process.argv[2]; | ||
const outputPath = process.argv[3]; | ||
// ensure that arguments are provided, and if not print usage | ||
if (!attributesPath || !outputPath) { | ||
console.error( | ||
"Please provide a path to the attributes.json file and a path to the desired output file.\nUsage: npx ts-node build-indexes.ts path/to/attributes.json path/to/output.sql" | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// read the attributes.json file | ||
const data = readFileSync(attributesPath, "utf8"); | ||
// parse the json | ||
const attributes = JSON.parse(data); | ||
|
||
// write the sql to the output file | ||
const outputSqlStream = createWriteStream(outputPath); | ||
|
||
for (const attribute of attributes) { | ||
if (attribute.attribute !== "id") { | ||
const statement = `CREATE INDEX if not exists idx_cells_${attribute.attribute} ON cells (${attribute.attribute});`; | ||
outputSqlStream.write(statement + "\n"); | ||
} | ||
} | ||
|
||
outputSqlStream.end(); | ||
|
||
console.log(`Wrote indexes to ${outputPath}`); | ||
// describe how to use sql file to populate indexes in postgres | ||
console.log(`Usage: psql -U postgres -d crdss -a -f ${outputPath}`); |
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