You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Initialize database and populate with example data
218
+
asyncfunctioninitDatabase(){
219
+
try{
220
+
displayStatus('Loading SQL.js...');
221
+
222
+
// Initialize SQL.js with the correct path to wasm file
223
+
constSQL=awaitinitSqlJs({
224
+
locateFile: file=>`./dist/${file}`
225
+
});
226
+
displayStatus('SQL.js loaded successfully!');
227
+
228
+
// Create a database
229
+
db=newSQL.Database();
230
+
displayStatus('Created an in-memory database');
231
+
232
+
// Create FTS5 virtual table
233
+
db.run(`
234
+
CREATE VIRTUAL TABLE articles USING fts5(
235
+
title,
236
+
body
237
+
);
238
+
`);
239
+
displayStatus('Created FTS5 virtual table');
240
+
241
+
// Insert example data
242
+
db.run(`
243
+
INSERT INTO articles (title, body) VALUES
244
+
('Introduction to SQL', 'SQL (Structured Query Language) is a standard language for storing, manipulating, and retrieving data in databases. SQL statements are used to perform tasks such as update data or retrieve data from a database.'),
245
+
('JavaScript Fundamentals', 'JavaScript is a programming language commonly used for web development. It allows you to implement complex features on web pages like interactive maps, animated graphics, and more.'),
246
+
('Python for Beginners', 'Python is a popular programming language. It was created by Guido van Rossum and released in 1991. It is used for web development, software development, mathematics, system scripting, and more.'),
247
+
('Web Development Basics', 'Web development refers to building, creating, and maintaining websites. It includes aspects such as web design, web publishing, web programming, and database management.'),
248
+
('Database Design Principles', 'Good database design is crucial for building scalable and efficient applications. It involves normalization, indexing strategies, and choosing the right data types.'),
249
+
('Machine Learning Introduction', 'Machine learning is a method of data analysis that automates analytical model building. It is a branch of artificial intelligence based on the idea that systems can learn from data.'),
250
+
('HTML and CSS Basics', 'HTML (Hypertext Markup Language) is the standard markup language for documents designed to be displayed in a web browser. CSS (Cascading Style Sheets) is used to style and layout web pages.'),
251
+
('Mobile App Development', 'Mobile app development involves creating applications that run on mobile devices. It requires considering screen sizes, hardware specifications, and various configurations.'),
252
+
('Cloud Computing Services', 'Cloud computing is the delivery of computing services over the internet. Services include servers, storage, databases, networking, software, and analytics.'),
253
+
('Cybersecurity Best Practices', 'Cybersecurity involves protecting systems, networks, and programs from digital attacks. These attacks often aim to access, change, or destroy sensitive information.')
254
+
`);
255
+
displayStatus('Database populated with example data');
256
+
257
+
// Show all articles initially
258
+
constinitialResults=db.exec('SELECT rowid, title, body FROM articles ORDER BY title');
0 commit comments