Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
65916ac9
Commit
65916ac9
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[ref] gva:schema: create macro exec_in_db_transaction to factor code
parent
97c7f91c
No related branches found
No related tags found
1 merge request
!238
[ref] gva:schema: create macro exec_in_db_transaction to factor code
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cargo.lock
+0
-1
0 additions, 1 deletion
Cargo.lock
lib/modules/gva/Cargo.toml
+0
-1
0 additions, 1 deletion
lib/modules/gva/Cargo.toml
lib/modules/gva/src/schema.rs
+31
-50
31 additions, 50 deletions
lib/modules/gva/src/schema.rs
with
31 additions
and
52 deletions
Cargo.lock
+
0
−
1
View file @
65916ac9
...
@@ -1050,7 +1050,6 @@ version = "0.1.0"
...
@@ -1050,7 +1050,6 @@ version = "0.1.0"
dependencies = [
dependencies = [
"actix-web 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"assert-json-diff 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"assert-json-diff 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-block-doc 0.1.0",
"dubp-block-doc 0.1.0",
"dubp-blocks-tests-tools 0.1.0",
"dubp-blocks-tests-tools 0.1.0",
...
...
This diff is collapsed.
Click to expand it.
lib/modules/gva/Cargo.toml
+
0
−
1
View file @
65916ac9
...
@@ -11,7 +11,6 @@ path = "src/lib.rs"
...
@@ -11,7 +11,6 @@ path = "src/lib.rs"
[dependencies]
[dependencies]
actix-web
=
"1.0.9"
actix-web
=
"1.0.9"
cfg-if
=
"0.1.10"
dubp-block-doc
=
{
path
=
"../../dubp/block-doc"
}
#, version = "0.1.0" }
dubp-block-doc
=
{
path
=
"../../dubp/block-doc"
}
#, version = "0.1.0" }
dup-crypto
=
{
path
=
"../../crypto"
}
dup-crypto
=
{
path
=
"../../crypto"
}
durs-bc-db-reader
=
{
path
=
"../../modules-lib/bc-db-reader"
,
features
=
[
"client-indexer"
]
}
durs-bc-db-reader
=
{
path
=
"../../modules-lib/bc-db-reader"
,
features
=
[
"client-indexer"
]
}
...
...
This diff is collapsed.
Click to expand it.
lib/modules/gva/src/schema.rs
+
31
−
50
View file @
65916ac9
...
@@ -33,6 +33,26 @@ use juniper_from_schema::graphql_schema_from_file;
...
@@ -33,6 +33,26 @@ use juniper_from_schema::graphql_schema_from_file;
// generate schema from schema file
// generate schema from schema file
graphql_schema_from_file!
(
"resources/schema.gql"
,
context_type
:
QueryContext
);
graphql_schema_from_file!
(
"resources/schema.gql"
,
context_type
:
QueryContext
);
/// Macro that execute a query resolver in db read transaction
#[cfg(not(test))]
macro_rules!
exec_in_db_transaction
{
(
$f:ident
(
$e:ident
,
$
(
$param:expr
),
*
))
=>
{
{
let
db
=
$e
.context
()
.get_db
();
db
.read
(|
r
|
queries
::
$f
::
execute
(
&
BcDbRoWithReader
{
db
,
r
}
$
(,
$param
)
*
))
.map_err
(
Into
::
into
)
}
};
}
#[cfg(test)]
macro_rules!
exec_in_db_transaction
{
(
$f:ident
(
$e:ident
,
$
(
$param:expr
),
*
))
=>
{
{
let
db
=
$e
.context
()
.get_db
();
queries
::
$f
::
execute
(
db
$
(,
$param
)
*
)
.map_err
(
Into
::
into
)
}
};
}
pub
struct
Query
;
pub
struct
Query
;
impl
QueryFields
for
Query
{
impl
QueryFields
for
Query
{
...
@@ -54,14 +74,7 @@ impl QueryFields for Query {
...
@@ -54,14 +74,7 @@ impl QueryFields for Query {
executor
:
&
Executor
<
'_
,
QueryContext
>
,
executor
:
&
Executor
<
'_
,
QueryContext
>
,
trail
:
&
QueryTrail
<
'_
,
Block
,
Walked
>
,
trail
:
&
QueryTrail
<
'_
,
Block
,
Walked
>
,
)
->
FieldResult
<
Option
<
Block
>>
{
)
->
FieldResult
<
Option
<
Block
>>
{
let
db
=
executor
.context
()
.get_db
();
exec_in_db_transaction!
(
current
(
executor
,
trail
))
cfg_if
::
cfg_if!
{
if
#[cfg(not(test))]
{
db
.read
(|
r
|
queries
::
current
::
execute
(
&
BcDbRoWithReader
{
db
,
r
},
trail
))
.map_err
(
Into
::
into
)
}
else
{
queries
::
current
::
execute
(
db
,
trail
)
.map_err
(
Into
::
into
)
}
}
}
}
#[inline]
#[inline]
fn
field_block
(
fn
field_block
(
...
@@ -70,14 +83,7 @@ impl QueryFields for Query {
...
@@ -70,14 +83,7 @@ impl QueryFields for Query {
trail
:
&
QueryTrail
<
'_
,
Block
,
Walked
>
,
trail
:
&
QueryTrail
<
'_
,
Block
,
Walked
>
,
number
:
i32
,
number
:
i32
,
)
->
FieldResult
<
Option
<
Block
>>
{
)
->
FieldResult
<
Option
<
Block
>>
{
let
db
=
executor
.context
()
.get_db
();
exec_in_db_transaction!
(
block
(
executor
,
trail
,
number
))
cfg_if
::
cfg_if!
{
if
#[cfg(not(test))]
{
db
.read
(|
r
|
queries
::
block
::
execute
(
&
BcDbRoWithReader
{
db
,
r
},
trail
,
number
))
.map_err
(
Into
::
into
)
}
else
{
queries
::
block
::
execute
(
db
,
trail
,
number
)
.map_err
(
Into
::
into
)
}
}
}
}
#[inline]
#[inline]
fn
field_blocks
(
fn
field_blocks
(
...
@@ -92,32 +98,14 @@ impl QueryFields for Query {
...
@@ -92,32 +98,14 @@ impl QueryFields for Query {
if
step
<=
0
{
if
step
<=
0
{
step
=
1
;
step
=
1
;
}
}
let
db
=
executor
.context
()
.get_db
();
exec_in_db_transaction!
(
blocks
(
cfg_if
::
cfg_if!
{
executor
,
if
#[cfg(not(test))]
{
db
.read
(|
r
|
{
queries
::
blocks
::
execute
(
&
BcDbRoWithReader
{
db
,
r
},
trail
,
paging_opt
,
block_interval_opt
,
step
as
usize
,
sort_order
,
)
})
.map_err
(
Into
::
into
)
}
else
{
queries
::
blocks
::
execute
(
db
,
trail
,
trail
,
paging_opt
,
paging_opt
,
block_interval_opt
,
block_interval_opt
,
step
as
usize
,
step
as
usize
,
sort_order
,
sort_order
)
))
.map_err
(
Into
::
into
)
}
}
}
}
#[inline]
#[inline]
fn
field_current_ud
(
fn
field_current_ud
(
...
@@ -125,14 +113,7 @@ impl QueryFields for Query {
...
@@ -125,14 +113,7 @@ impl QueryFields for Query {
executor
:
&
Executor
<
'_
,
QueryContext
>
,
executor
:
&
Executor
<
'_
,
QueryContext
>
,
trail
:
&
QueryTrail
<
'_
,
CurrentUd
,
Walked
>
,
trail
:
&
QueryTrail
<
'_
,
CurrentUd
,
Walked
>
,
)
->
FieldResult
<
Option
<
CurrentUd
>>
{
)
->
FieldResult
<
Option
<
CurrentUd
>>
{
let
db
=
executor
.context
()
.get_db
();
exec_in_db_transaction!
(
current_ud
(
executor
,
trail
))
cfg_if
::
cfg_if!
{
if
#[cfg(not(test))]
{
db
.read
(|
r
|
queries
::
current_ud
::
execute
(
&
BcDbRoWithReader
{
db
,
r
},
trail
))
.map_err
(
Into
::
into
)
}
else
{
queries
::
current_ud
::
execute
(
db
,
trail
)
.map_err
(
Into
::
into
)
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment