-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fee5db1
commit dc715c7
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const sqlite3 = require('sqlite3').verbose() | ||
|
||
var db = new sqlite3.Database('./user.db', sqlite3.OPEN_READWRITE, function (err) { | ||
if (err) { | ||
return console.log(err.message) | ||
} | ||
console.log('connect database successfully') | ||
}) | ||
|
||
db.serialize(function () { | ||
db.run('CREATE TABLE user(name text)', function (err) { | ||
if (err) { | ||
return console.log(err) | ||
|
||
} | ||
console.log('create table user') | ||
}) | ||
|
||
|
||
db.run('INSERT INTO user(name) VALUES(?), (?)', ['Alice', 'Jack'], function (err) { | ||
if (err) { | ||
return console.log('insert data error: ', err.message) | ||
} | ||
console.log('insert data: ', this) | ||
}) | ||
|
||
db.all('SELECT name FROM user WHERE name = ?', ['Alice'], function (err, rows) { | ||
if (err) { | ||
return console.log('find Alice error: ', err.message) | ||
} | ||
|
||
console.log('find Alice: ', rows) | ||
}) | ||
|
||
db.run('UPDATE user SET name = ? WHERE name = ?', ['Alin', 'Alice'], function (err) { | ||
if (err) { | ||
return console.log('update data error: ', err.message) | ||
} | ||
console.log('update data: ', this) | ||
}) | ||
|
||
db.all('SELECT * FROM user', [], function (err, rows) { | ||
if (err) { | ||
return console.log('find error: ', err) | ||
} | ||
console.log('find updated data', rows) | ||
}) | ||
|
||
db.run('DELETE FROM user WHERE name = ?', ['Alin'], function (err) { | ||
if (err) { | ||
return console.log(err.message) | ||
} | ||
console.log('deleted Alin: ', this) | ||
}) | ||
}) | ||
|
||
db.close(function (err) { | ||
if (err) { | ||
return console.log(err.message) | ||
} | ||
console.log('close database connection') | ||
}) |
Empty file.