@@ -2,7 +2,12 @@ import fs from 'node:fs'
22import path from 'node:path'
33import { get_client } from './shared'
44import 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
712const 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
3138function 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+ }
0 commit comments