Skip to content

Commit

Permalink
Set up keydata table and save datetimed entries
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Jan 8, 2025
1 parent 885bb10 commit b4c518c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
4 changes: 3 additions & 1 deletion build-filtered-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ async function filterDeps () {
)

console.log('Getting key data')
const keyData = await db.getKeyData()
const keyData = await db.getKeyDataFromResults()
keyData.date = new Date().toISOString()
db.insertKeyData(keyData)
await appendFileSync(
`data/${yyyymmdd}-${timestamp}-key-data.json`,
JSON.stringify(keyData, null, 2)
Expand Down
57 changes: 56 additions & 1 deletion helpers/database.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ export class RepoDB {
`)
setup.run()

const keyDataSetup = this.db.prepare(`
CREATE TABLE IF NOT EXISTS keyData (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date TEXT,
Total INTEGER,
NumberBuiltByGovernment INTEGER,
VersionUnknown INTEGER,
version0 INTEGER,
version1 INTEGER,
version2 INTEGER,
version3 INTEGER,
version4 INTEGER,
version5 INTEGER,
prototypes INTEGER,
activeRepos INTEGER,
errors INTEGER
)`)
keyDataSetup.run()

// Create an index on repoOwner and repoName for faster lookups
const indexSetup = this.db.prepare(`
CREATE INDEX IF NOT EXISTS idx_repo_owner_name ON repos (repoOwner, repoName)
Expand Down Expand Up @@ -98,7 +117,43 @@ export class RepoDB {
}
}

getKeyData () {
insertKeyData (stats) {
const insertKeyData = this.db.prepare(`
INSERT OR REPLACE INTO keyData (
date,
Total,
NumberBuiltByGovernment,
VersionUnknown,
version0,
version1,
version2,
version3,
version4,
version5,
prototypes,
activeRepos,
errors
) VALUES (
@date,
@Total,
@NumberBuiltByGovernment,
@VersionUnknown,
@version0,
@version1,
@version2,
@version3,
@version4,
@version5,
@prototypes,
@activeRepos,
@errors
)
`)

insertKeyData.run(stats)
}

getKeyDataFromResults () {
const query = this.db.prepare(`
SELECT
(SELECT COUNT(*) FROM repos) AS Total,
Expand Down

0 comments on commit b4c518c

Please sign in to comment.