Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-devlop-rest-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
zhouzihao
node-devlop-rest-api
Commits
58e43f53
Commit
58e43f53
authored
Mar 26, 2020
by
zhouzihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix-修改保存问题
parent
39c8506b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
tools/databaseHelper.js
tools/databaseHelper.js
+9
-7
No files found.
tools/databaseHelper.js
View file @
58e43f53
...
...
@@ -11,14 +11,14 @@ var saveJsonToDb = (json, table, key) => {
return
new
Promise
((
resovle
,
reject
)
=>
{
var
sql
=
""
;
if
(
_
.
has
(
json
,
key
)
&&
_
.
get
(
json
,
key
,
0
)
>
0
)
{
var
id
=
_
.
get
(
json
,
key
);
_
.
unset
(
json
,
key
);
var
jsonClone
=
Object
.
assign
({},
json
);
_
.
unset
(
json
Clone
,
key
);
var
where
=
{};
where
[
key
]
=
id
;
where
[
key
]
=
_
.
get
(
json
,
key
);
;
// update
sql
=
db
.
sql
.
$update
({
$table
:
table
,
$set
:
json
,
$set
:
json
Clone
,
$where
:
where
});
}
else
{
...
...
@@ -32,7 +32,9 @@ var saveJsonToDb = (json, table, key) => {
db
.
query
(
sql
.
sql
,
sql
.
values
)
.
then
((
rows
)
=>
{
// console.log(JSON.stringify(rows));
json
[
key
]
=
rows
.
insertId
;
if
(
rows
.
insertId
>
0
)
{
json
[
key
]
=
rows
.
insertId
;
}
resovle
(
json
);
}).
catch
((
err
)
=>
{
reject
(
JSON
.
stringify
(
err
));
...
...
@@ -114,7 +116,7 @@ var countByJson = (json, table, key) => {
* @param {*} page
* @param {*} pageSize
*/
var
pagedDbByJson
=
(
json
,
table
,
items
,
key
,
page
=
1
,
pageSize
=
10
,
orderby
=
""
)
=>
{
var
pagedDbByJson
=
(
json
,
table
,
items
,
key
,
page
=
1
,
pageSize
=
10
,
orderby
=
""
)
=>
{
return
new
Promise
((
resovle
,
reject
)
=>
{
countByJson
(
json
,
table
,
key
)
.
then
((
len
)
=>
{
...
...
@@ -123,7 +125,7 @@ var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10,orderby=""
$limit
:
pageSize
,
$offset
:
(
page
-
1
)
*
pageSize
,
}
if
(
!
_
.
isEmpty
){
if
(
!
_
.
isEmpty
)
{
extra
[
'
$orderby
'
]
=
orderby
;
}
return
listDbByJson
(
json
,
table
,
items
,
extra
).
then
((
data
)
=>
{
...
...
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