Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sqlite3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
node-sqlite3
Commits
0d76b3f9
Commit
0d76b3f9
authored
Jun 07, 2018
by
Bryce Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upsert test.
parent
ef1bad48
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
upsert.test.js
test/upsert.test.js
+27
-0
No files found.
test/upsert.test.js
0 → 100644
View file @
0d76b3f9
var
sqlite3
=
require
(
'..'
);
var
assert
=
require
(
'assert'
);
describe
(
'query properties'
,
function
()
{
var
db
;
before
(
function
(
done
)
{
db
=
new
sqlite3
.
Database
(
':memory:'
);
db
.
run
(
"CREATE TABLE foo (id INT PRIMARY KEY, count INT)"
,
done
);
});
it
(
'should upsert'
,
function
(
done
)
{
var
stmt
=
db
.
prepare
(
"INSERT INTO foo VALUES(?, ?)"
);
stmt
.
run
(
1
,
1
,
function
(
err
)
{
// insert 1
if
(
err
)
throw
err
;
var
upsert_stmt
=
db
.
prepare
(
"INSERT INTO foo VALUES(?, ?) ON CONFLICT (id) DO UPDATE SET count = count + excluded.count"
);
upsert_stmt
.
run
(
1
,
2
,
function
(
err
)
{
// add 2
if
(
err
)
throw
err
;
var
select_stmt
=
db
.
prepare
(
"SELECT count FROM foo WHERE id = ?"
);
select_stmt
.
get
(
1
,
function
(
err
,
row
)
{
if
(
err
)
throw
err
;
assert
.
equal
(
row
.
count
,
3
);
// equals 3
});
})
});
db
.
wait
(
done
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment