MCPcopy Create free account
hub / github.com/angular/dev-infra / generate

Function generate

bazel/rules/rules_angular/src/ng_examples_db/db_generator.mjs:83–209  ·  view source on GitHub ↗
(inPath, outPath)

Source from the content-addressed store, hash-verified

81}
82
83export function generate(inPath, outPath) {
84 const dbPath = outPath;
85 mkdirSync(dirname(outPath), {recursive: true});
86
87 if (existsSync(dbPath)) {
88 rmSync(dbPath);
89 }
90 const db = new DatabaseSync(dbPath);
91
92 // Create a table to store metadata.
93 db.exec(`
94 CREATE TABLE metadata (
95 key TEXT PRIMARY KEY NOT NULL,
96 value TEXT NOT NULL
97 );
98 `);
99
100 db.exec(`
101 INSERT INTO metadata (key, value) VALUES
102 ('schema_version', '1'),
103 ('created_at', '${new Date().toISOString()}');
104 `);
105
106 // Create a relational table to store the structured example data.
107 db.exec(`
108 CREATE TABLE examples (
109 id INTEGER PRIMARY KEY,
110 title TEXT NOT NULL,
111 summary TEXT NOT NULL,
112 keywords TEXT,
113 required_packages TEXT,
114 related_concepts TEXT,
115 related_tools TEXT,
116 experimental INTEGER NOT NULL DEFAULT 0,
117 content TEXT NOT NULL
118 );
119 `);
120
121 // Create an FTS5 virtual table to provide full-text search capabilities.
122 db.exec(`
123 CREATE VIRTUAL TABLE examples_fts USING fts5(
124 title,
125 summary,
126 keywords,
127 required_packages,
128 related_concepts,
129 related_tools,
130 content,
131 content='examples',
132 content_rowid='id',
133 tokenize = 'porter ascii'
134 );
135 `);
136
137 // Create triggers to keep the FTS table synchronized with the examples table.
138 db.exec(`
139 CREATE TRIGGER examples_after_insert AFTER INSERT ON examples BEGIN
140 INSERT INTO examples_fts(

Callers 1

mainFunction · 0.85

Calls 7

resolveFunction · 0.85
parseFrontmatterFunction · 0.85
execMethod · 0.45
errorMethod · 0.45
runMethod · 0.45
stringifyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected