Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WikaSilo #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
node_modules
1 change: 1 addition & 0 deletions README0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# poll-db-1
44 changes: 44 additions & 0 deletions module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const sqlite3 = require('sqlite3').verbose();
const fs = require('fs');

// const db = new sqlite3.Database('./poll.db');

// let politicians = fs.readFileSync('./politicians.csv', 'utf8').trim().split('\n');
// let voters = fs.readFileSync('./voters.csv', 'utf8').trim().split('\n');
// let votes = fs.readFileSync('./votes.csv', 'utf8').trim().split('\n');

function newData(namaTable, name, party, location, grade_current) {
const db = new sqlite3.Database('./poll.db');
let temp = fs.readFileSync(`./${namaTable}.csv`, 'utf8').trim().split('\n');

var stmt = db.prepare(`INSERT INTO ${namaTable}(name, party, location, grade_current) VALUES (?, ?, ?, ?)`);
stmt.run([name, party, location, grade_current]);
stmt.finalize();
console.log(`Berhasil menambah data ${namaTable}`);
}

// newData('politicians','wika', 'w', 'ny', 11.2231231)

function deleteData(namaTable, id) {
const db = new sqlite3.Database('./poll.db');
let temp = fs.readFileSync(`./${namaTable}.csv`, 'utf8').trim().split('\n');

var stmt = db.prepare(`DELETE FROM ${namaTable} WHERE id = ?`);
stmt.run([id]);
stmt.finalize();
console.log(`Berhasil menghapus data ${id} pada table ${namaTable}`);
}

// deleteData('politicians',22);

function updateData(namaTable, colomnName, colomnValue, id) {
const db = new sqlite3.Database('./poll.db');
let temp = fs.readFileSync(`./${namaTable}.csv`, 'utf8').trim().split('\n');

var stmt = db.prepare(`UPDATE ${namaTable} SET ${colomnName} = ? WHERE id = ?`);
stmt.run([colomnValue, id]);
stmt.finalize();
console.log(`Berhasil mengupdate data ${id} pada table ${namaTable}`);
}

updateData('politicians','party','R',1);
Loading