Skip to content

Commit efb84de

Browse files
committed
seed lemmas
1 parent d84bc71 commit efb84de

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

databases/catdat/scripts/seed.yaml.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import fs from 'node:fs'
22
import path from 'node:path'
33
import { get_client } from './shared'
44
import YAML from 'yaml'
5-
import type { CategoryYaml, ConfigYaml, CategoryPropertyYaml } from './yaml.types'
5+
import type {
6+
CategoryYaml,
7+
ConfigYaml,
8+
CategoryPropertyYaml,
9+
LemmaYaml,
10+
} from './yaml.types'
611

712
const db = get_client()
813

@@ -19,13 +24,15 @@ function seed() {
1924
clear_all_data()
2025

2126
seed_config()
27+
28+
seed_lemmas()
2229
seed_category_properties()
2330
seed_categories()
2431

2532
// TODO: seed implications
2633
// TODO: seed category property assignments
2734
// TODO: seed category property comments
28-
// TODO: seed lemmas, and all the other tables
35+
// TODO: seed all the other tables
2936
}
3037

3138
function clear_all_data() {
@@ -241,3 +248,25 @@ function seed_category_properties() {
241248
}
242249
})()
243250
}
251+
252+
function seed_lemmas() {
253+
const lemma_folder = path.join(data_folder, 'lemmas')
254+
255+
const lemma_files = fs
256+
.readdirSync(lemma_folder)
257+
.filter((file) => file.endsWith('.yaml'))
258+
.sort()
259+
260+
const lemma_insert = db.prepare(
261+
`INSERT INTO lemmas (id, title, claim, proof) VALUES (?, ?, ?, ?)`,
262+
)
263+
264+
db.transaction(() => {
265+
for (const lemma_file of lemma_files) {
266+
const content = fs.readFileSync(path.join(lemma_folder, lemma_file), 'utf8')
267+
const lemma = YAML.parse(content) as LemmaYaml
268+
269+
lemma_insert.run(lemma.id, lemma.title, lemma.claim, lemma.proof)
270+
}
271+
})()
272+
}

databases/catdat/scripts/yaml.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ export type CategoryPropertyYaml = {
6161
invariant_under_equivalences: boolean
6262
related_properties: string[]
6363
}
64+
65+
export type LemmaYaml = {
66+
id: string
67+
title: string
68+
claim: string
69+
proof: string
70+
}

0 commit comments

Comments
 (0)