Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
David Kosztka
Pod
Commits
32427605
Unverified
Commit
32427605
authored
3 years ago
by
Vasili Novikov
Browse files
Options
Download
Email Patches
Plain Diff
Fix formatting
parent
61462b90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/database_api.rs
+3
-6
src/database_api.rs
src/database_utils.rs
+23
-15
src/database_utils.rs
with
26 additions
and
21 deletions
+26
-21
src/database_api.rs
+
3
-
6
View file @
32427605
...
...
@@ -300,18 +300,15 @@ pub fn check_real_exists(tx: &Tx, item_rowid: Rowid, name: &str, value: f64) ->
}
pub
fn
check_integer_exists_by_name
(
tx
:
&
Tx
,
item_rowid
:
Rowid
,
name
:
&
str
)
->
Result
<
bool
>
{
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM integers WHERE item = ? AND name = ?;"
)
?
;
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM integers WHERE item = ? AND name = ?;"
)
?
;
Ok
(
stmt
.exists
(
params!
[
item_rowid
,
name
])
?
)
}
pub
fn
check_string_exists_by_name
(
tx
:
&
Tx
,
item_rowid
:
Rowid
,
name
:
&
str
)
->
Result
<
bool
>
{
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM strings WHERE item = ? AND name = ?;"
)
?
;
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM strings WHERE item = ? AND name = ?;"
)
?
;
Ok
(
stmt
.exists
(
params!
[
item_rowid
,
name
])
?
)
}
pub
fn
check_real_exists_by_name
(
tx
:
&
Tx
,
item_rowid
:
Rowid
,
name
:
&
str
)
->
Result
<
bool
>
{
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM reals WHERE item = ? AND name = ?;"
)
?
;
let
mut
stmt
=
tx
.prepare_cached
(
"SELECT 1 FROM reals WHERE item = ? AND name = ?;"
)
?
;
Ok
(
stmt
.exists
(
params!
[
item_rowid
,
name
])
?
)
}
...
...
This diff is collapsed.
Click to expand it.
src/database_utils.rs
+
23
-
15
View file @
32427605
...
...
@@ -123,14 +123,24 @@ pub fn check_item_has_property(
match
value
{
Value
::
Null
=>
{
let
exists
=
match
dbtype
{
SchemaPropertyType
::
Text
=>
database_api
::
check_string_exists_by_name
(
tx
,
rowid
,
name
)
?
,
SchemaPropertyType
::
Integer
=>
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
,
SchemaPropertyType
::
Real
=>
database_api
::
check_real_exists_by_name
(
tx
,
rowid
,
name
)
?
,
SchemaPropertyType
::
Bool
=>
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
,
SchemaPropertyType
::
DateTime
=>
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
,
SchemaPropertyType
::
Text
=>
{
database_api
::
check_string_exists_by_name
(
tx
,
rowid
,
name
)
?
}
SchemaPropertyType
::
Integer
=>
{
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
}
SchemaPropertyType
::
Real
=>
{
database_api
::
check_real_exists_by_name
(
tx
,
rowid
,
name
)
?
}
SchemaPropertyType
::
Bool
=>
{
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
}
SchemaPropertyType
::
DateTime
=>
{
database_api
::
check_integer_exists_by_name
(
tx
,
rowid
,
name
)
?
}
};
Ok
(
!
exists
)
}
,
}
Value
::
String
(
value
)
if
dbtype
==
&
SchemaPropertyType
::
Text
=>
{
database_api
::
check_string_exists
(
tx
,
rowid
,
name
,
value
)
}
...
...
@@ -173,15 +183,13 @@ pub fn check_item_has_property(
})
}
}
_
=>
{
Err
(
Error
{
code
:
StatusCode
::
BAD_REQUEST
,
msg
:
format!
(
"Failed to parse json value {} to {:?} ({})"
,
value
,
dbtype
,
name
),
})
}
_
=>
Err
(
Error
{
code
:
StatusCode
::
BAD_REQUEST
,
msg
:
format!
(
"Failed to parse json value {} to {:?} ({})"
,
value
,
dbtype
,
name
),
}),
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets