/
lostSun
/
project-client-server-apps
Обзор
Документация
Войти
/
lostSun
/
project-client-server-apps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
server/src/db/seed.js
60 строк
1 KB
1lostsun
update project
25 май 2025, 13:12
25 май 2025, 13:12
78a0079
Код
Авторство
О чём код?
const sqlite3 = require('sqlite3').verbose(); const path = require('path'); const db = new sqlite3.Database(path.join(__dirname, 'database.sqlite')); const books = [ { title: '1984', author: 'George Orwell', description: 'A dystopian novel set in a totalitarian society.', year: 1949, isbn: '978-0451524935' }, { title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', description: 'A story of decadence and excess.', year: 1925, isbn: '978-0743273565' }, { title: 'To Kill a Mockingbird', author: 'Harper Lee', description: 'A novel about racism and injustice in the American South.', year: 1960, isbn: '978-0446310789' }, { title: 'Pride and Prejudice', author: 'Jane Austen', description: 'A romantic novel about the Bennet family.', year: 1813, isbn: '978-0141439518' }, { title: 'The Catcher in the Rye', author: 'J.D. Salinger', description: 'A story of teenage alienation and loss of innocence.', year: 1951, isbn: '978-0316769488' } ]; db.serialize(() => { // Очищаем таблицу db.run('DELETE FROM books'); // Добавляем тестовые данные const stmt = db.prepare('INSERT INTO books (title, author, description, year, isbn) VALUES (?, ?, ?, ?, ?)'); books.forEach(book => { stmt.run(book.title, book.author, book.description, book.year, book.isbn); }); stmt.finalize(); }); db.close(() => { console.log('Database seeded!'); });