Skip to content

Commit ab692ae

Browse files
author
Zoran Cvetkov
committed
more lifetime
1 parent e29c0b1 commit ab692ae

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ struct QueryValue<'a>(&'a Value, &'a ColumnType);
537537

538538
impl<'a> QueryFragment<Pg> for QueryValue<'a> {
539539
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
540-
let out = &mut out;
541540
out.unsafe_to_cache_prepared();
542541
let column_type = self.1;
543542

@@ -1105,12 +1104,12 @@ impl<'a> QueryFilter<'a> {
11051104
.expect("the constructor already checked that all attribute names are valid")
11061105
}
11071106

1108-
fn binary_op(
1109-
&self,
1110-
filters: &[EntityFilter],
1107+
fn binary_op<'b>(
1108+
&'b self,
1109+
filters: &'b [EntityFilter],
11111110
op: &str,
11121111
on_empty: &str,
1113-
mut out: AstPass<Pg>,
1112+
mut out: AstPass<'_, 'b, Pg>,
11141113
) -> QueryResult<()> {
11151114
if !filters.is_empty() {
11161115
out.push_sql("(");
@@ -1127,13 +1126,13 @@ impl<'a> QueryFilter<'a> {
11271126
Ok(())
11281127
}
11291128

1130-
fn contains(
1131-
&self,
1129+
fn contains<'b>(
1130+
&'b self,
11321131
attribute: &Attribute,
1133-
value: &Value,
1132+
value: &'b Value,
11341133
negated: bool,
11351134
strict: bool,
1136-
mut out: AstPass<Pg>,
1135+
mut out: AstPass<'_, 'b, Pg>,
11371136
) -> QueryResult<()> {
11381137
let column = self.column(attribute);
11391138
let operation = match (strict, negated) {
@@ -1199,12 +1198,12 @@ impl<'a> QueryFilter<'a> {
11991198
Ok(())
12001199
}
12011200

1202-
fn equals(
1203-
&self,
1201+
fn equals<'b>(
1202+
&'b self,
12041203
attribute: &Attribute,
12051204
value: &Value,
12061205
op: Comparison,
1207-
mut out: AstPass<Pg>,
1206+
mut out: AstPass<'_, 'b, Pg>,
12081207
) -> QueryResult<()> {
12091208
let column = self.column(attribute);
12101209

@@ -1480,14 +1479,14 @@ pub struct FindQuery<'a> {
14801479
}
14811480

14821481
impl<'a> QueryFragment<Pg> for FindQuery<'a> {
1483-
fn walk_ast(&self, mut out: AstPass<Pg>) -> QueryResult<()> {
1482+
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
14841483
out.unsafe_to_cache_prepared();
14851484

14861485
// Generate
14871486
// select '..' as entity, to_jsonb(e.*) as data
14881487
// from schema.table e where id = $1
14891488
out.push_sql("select ");
1490-
out.push_bind_param::<Text, _>(&self.table.object.as_str())?;
1489+
out.push_bind_param::<Text, _>(self.table.object.as_str())?;
14911490
out.push_sql(" as entity, to_jsonb(e.*) as data\n");
14921491
out.push_sql(" from ");
14931492
out.push_sql(self.table.qualified_name.as_str());
@@ -1534,7 +1533,7 @@ impl<'a> QueryFragment<Pg> for FindChangesQuery<'a> {
15341533
out.push_sql("\nunion all\n");
15351534
}
15361535
out.push_sql("select ");
1537-
out.push_bind_param::<Text, _>(&table.object.as_str())?;
1536+
out.push_bind_param::<Text, _>(table.object.as_str())?;
15381537
out.push_sql(" as entity, to_jsonb(e.*) as data\n");
15391538
out.push_sql(" from ");
15401539
out.push_sql(table.qualified_name.as_str());
@@ -1574,7 +1573,7 @@ pub struct FindPossibleDeletionsQuery<'a> {
15741573
}
15751574

15761575
impl<'a> QueryFragment<Pg> for FindPossibleDeletionsQuery<'a> {
1577-
fn walk_ast(&self, mut out: AstPass<Pg>) -> QueryResult<()> {
1576+
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
15781577
let out = &mut out;
15791578
out.unsafe_to_cache_prepared();
15801579

@@ -1583,7 +1582,7 @@ impl<'a> QueryFragment<Pg> for FindPossibleDeletionsQuery<'a> {
15831582
out.push_sql("\nunion all\n");
15841583
}
15851584
out.push_sql("select ");
1586-
out.push_bind_param::<Text, _>(&table.object.as_str())?;
1585+
out.push_bind_param::<Text, _>(table.object.as_str())?;
15871586
out.push_sql(" as entity, ");
15881587
if table.has_causality_region {
15891588
out.push_sql("causality_region, ");
@@ -1639,7 +1638,7 @@ impl<'a> QueryFragment<Pg> for FindManyQuery<'a> {
16391638
out.push_sql("\nunion all\n");
16401639
}
16411640
out.push_sql("select ");
1642-
out.push_bind_param::<Text, _>(&table.object.as_str())?;
1641+
out.push_bind_param::<Text, _>(table.object.as_str())?;
16431642
out.push_sql(" as entity, to_jsonb(e.*) as data\n");
16441643
out.push_sql(" from ");
16451644
out.push_sql(table.qualified_name.as_str());
@@ -1696,7 +1695,7 @@ impl<'a> QueryFragment<Pg> for FindDerivedQuery<'a> {
16961695
// select '..' as entity, to_jsonb(e.*) as data
16971696
// from schema.table e where field = $1
16981697
out.push_sql("select ");
1699-
out.push_bind_param::<Text, _>(&self.table.object.as_str())?;
1698+
out.push_bind_param::<Text, _>(self.table.object.as_str())?;
17001699
out.push_sql(" as entity, to_jsonb(e.*) as data\n");
17011700
out.push_sql(" from ");
17021701
out.push_sql(self.table.qualified_name.as_str());
@@ -1876,7 +1875,7 @@ impl<'a> InsertQuery<'a> {
18761875
}
18771876

18781877
impl<'a> QueryFragment<Pg> for InsertQuery<'a> {
1879-
fn walk_ast(&self, mut out: AstPass<Pg>) -> QueryResult<()> {
1878+
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
18801879
let out = &mut out;
18811880
out.unsafe_to_cache_prepared();
18821881

@@ -1984,7 +1983,7 @@ impl<'a> QueryFragment<Pg> for ConflictingEntityQuery<'a> {
19841983
out.push_sql("\nunion all\n");
19851984
}
19861985
out.push_sql("select ");
1987-
out.push_bind_param::<Text, _>(&table.object.as_str())?;
1986+
out.push_bind_param::<Text, _>(table.object.as_str())?;
19881987
out.push_sql(" as entity from ");
19891988
out.push_sql(table.qualified_name.as_str());
19901989
out.push_sql(" where id = ");
@@ -2073,17 +2072,17 @@ enum ParentLimit<'a> {
20732072
}
20742073

20752074
impl<'a> ParentLimit<'a> {
2076-
fn filter(&self, mut out: AstPass<'_, 'a, Pg>) {
2075+
fn filter(&self, out: &mut AstPass<'_, 'a, Pg>) {
20772076
match self {
20782077
ParentLimit::Outer => out.push_sql(" and q.id = p.id"),
20792078
ParentLimit::Ranked(_, _) => (),
20802079
}
20812080
}
20822081

2083-
fn restrict<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
2082+
fn restrict(&'a self, out: &mut AstPass<'_, 'a, Pg>) -> QueryResult<()> {
20842083
if let ParentLimit::Ranked(sort_key, range) = self {
20852084
out.push_sql(" ");
2086-
sort_key.order_by(&mut out, false)?;
2085+
sort_key.order_by(out, false)?;
20872086
range.walk_ast(out.reborrow())?;
20882087
}
20892088
Ok(())
@@ -2177,7 +2176,7 @@ impl<'a> FilterWindow<'a> {
21772176
fn children_type_a<'b>(
21782177
&'b self,
21792178
column: &Column,
2180-
limit: ParentLimit<'b>,
2179+
limit: &'b ParentLimit<'_>,
21812180
block: BlockNumber,
21822181
out: &mut AstPass<'_, 'b, Pg>,
21832182
) -> QueryResult<()> {
@@ -2202,20 +2201,20 @@ impl<'a> FilterWindow<'a> {
22022201
out.push_sql(self.table.qualified_name.as_str());
22032202
out.push_sql(" c where ");
22042203
BlockRangeColumn::new(self.table, "c.", block).contains(out, false)?;
2205-
limit.filter(out.reborrow());
2204+
limit.filter(out);
22062205
out.push_sql(" and p.id = any(c.");
22072206
out.push_identifier(column.name.as_str())?;
22082207
out.push_sql(")");
22092208
self.and_filter(out)?;
2210-
limit.restrict(out.reborrow())?;
2209+
limit.restrict(out)?;
22112210
out.push_sql(") c");
22122211
Ok(())
22132212
}
22142213

22152214
fn child_type_a<'b>(
22162215
&'b self,
22172216
column: &Column,
2218-
limit: ParentLimit<'b>,
2217+
limit: &'b ParentLimit<'_>,
22192218
block: BlockNumber,
22202219
out: &mut AstPass<'_, 'b, Pg>,
22212220
) -> QueryResult<()> {
@@ -2238,7 +2237,7 @@ impl<'a> FilterWindow<'a> {
22382237
out.push_sql(self.table.qualified_name.as_str());
22392238
out.push_sql(" c where ");
22402239
BlockRangeColumn::new(self.table, "c.", block).contains(out, false)?;
2241-
limit.filter(out.reborrow());
2240+
limit.filter(out);
22422241
out.push_sql(" and c.");
22432242
out.push_identifier(column.name.as_str())?;
22442243
out.push_sql(" @> array[p.id]");
@@ -2256,7 +2255,7 @@ impl<'a> FilterWindow<'a> {
22562255
fn children_type_b<'b>(
22572256
&'b self,
22582257
column: &Column,
2259-
limit: ParentLimit<'b>,
2258+
limit: &'b ParentLimit<'_>,
22602259
block: BlockNumber,
22612260
out: &mut AstPass<'_, 'b, Pg>,
22622261
) -> QueryResult<()> {
@@ -2281,19 +2280,19 @@ impl<'a> FilterWindow<'a> {
22812280
out.push_sql(self.table.qualified_name.as_str());
22822281
out.push_sql(" c where ");
22832282
BlockRangeColumn::new(self.table, "c.", block).contains(out, false)?;
2284-
limit.filter(out.reborrow());
2283+
limit.filter(out);
22852284
out.push_sql(" and p.id = c.");
22862285
out.push_identifier(column.name.as_str())?;
22872286
self.and_filter(out)?;
2288-
limit.restrict(out.reborrow())?;
2287+
limit.restrict(out)?;
22892288
out.push_sql(") c");
22902289
Ok(())
22912290
}
22922291

22932292
fn child_type_b<'b>(
22942293
&'b self,
22952294
column: &Column,
2296-
limit: ParentLimit<'b>,
2295+
limit: &'b ParentLimit<'_>,
22972296
block: BlockNumber,
22982297
out: &mut AstPass<'_, 'b, Pg>,
22992298
) -> QueryResult<()> {
@@ -2311,7 +2310,7 @@ impl<'a> FilterWindow<'a> {
23112310
out.push_sql(self.table.qualified_name.as_str());
23122311
out.push_sql(" c where ");
23132312
BlockRangeColumn::new(self.table, "c.", block).contains(out, false)?;
2314-
limit.filter(out.reborrow());
2313+
limit.filter(out);
23152314
out.push_sql(" and p.id = c.");
23162315
out.push_identifier(column.name.as_str())?;
23172316
self.and_filter(out)?;
@@ -2322,7 +2321,7 @@ impl<'a> FilterWindow<'a> {
23222321
fn children_type_c<'b>(
23232322
&'b self,
23242323
child_ids: &'b [IdList],
2325-
limit: ParentLimit<'b>,
2324+
limit: &'b ParentLimit<'_>,
23262325
block: BlockNumber,
23272326
out: &mut AstPass<'_, 'b, Pg>,
23282327
) -> QueryResult<()> {
@@ -2366,10 +2365,10 @@ impl<'a> FilterWindow<'a> {
23662365
out.push_sql(self.table.qualified_name.as_str());
23672366
out.push_sql(" c where ");
23682367
BlockRangeColumn::new(self.table, "c.", block).contains(out, true);
2369-
limit.filter(out.reborrow());
2368+
limit.filter(out);
23702369
out.push_sql(" and c.id = any(p.child_ids)");
23712370
self.and_filter(out)?;
2372-
limit.restrict(out.reborrow())?;
2371+
limit.restrict(out)?;
23732372
out.push_sql(") c");
23742373
} else {
23752374
// Generate
@@ -2390,7 +2389,7 @@ impl<'a> FilterWindow<'a> {
23902389
fn child_type_d<'b>(
23912390
&'b self,
23922391
child_ids: &'b IdList,
2393-
limit: ParentLimit<'b>,
2392+
limit: &'b ParentLimit<'_>,
23942393
block: BlockNumber,
23952394
out: &mut AstPass<'_, 'b, Pg>,
23962395
) -> QueryResult<()> {
@@ -2408,7 +2407,7 @@ impl<'a> FilterWindow<'a> {
24082407
out.push_sql(self.table.qualified_name.as_str());
24092408
out.push_sql(" c where ");
24102409
BlockRangeColumn::new(self.table, "c.", block).contains(out, true)?;
2411-
limit.filter(out.reborrow());
2410+
limit.filter(out);
24122411

24132412
// Include a constraint on the child IDs as a set if the size of the set
24142413
// is below the threshold set by environment variable. Set it to
@@ -2431,7 +2430,7 @@ impl<'a> FilterWindow<'a> {
24312430

24322431
fn children<'b>(
24332432
&'b self,
2434-
limit: ParentLimit<'b>,
2433+
limit: &'b ParentLimit<'_>,
24352434
block: BlockNumber,
24362435
out: &mut AstPass<'_, 'b, Pg>,
24372436
) -> QueryResult<()> {
@@ -2473,7 +2472,7 @@ impl<'a> FilterWindow<'a> {
24732472
out.push_sql("' as entity, c.id, c.vid, p.id::text as ");
24742473
out.push_sql(&*PARENT_ID);
24752474
sort_key.select(&mut out, SelectStatementLevel::InnerStatement)?;
2476-
self.children(ParentLimit::Outer, block, &mut out)
2475+
self.children(&ParentLimit::Outer, block, &mut out)
24772476
}
24782477

24792478
/// Collect all the parent id's from all windows
@@ -3646,14 +3645,18 @@ impl<'a> SortKey<'a> {
36463645
Ok(())
36473646
}
36483647

3649-
fn add_child(&self, block: BlockNumber, out: &mut AstPass<Pg>) -> QueryResult<()> {
3650-
fn add(
3651-
block: BlockNumber,
3648+
fn add_child<'b>(
3649+
&self,
3650+
block: &'b BlockNumber,
3651+
out: &mut AstPass<'_, 'b, Pg>,
3652+
) -> QueryResult<()> {
3653+
fn add<'b>(
3654+
block: &'b BlockNumber,
36523655
child_table: &Table,
36533656
child_column: &Column,
36543657
parent_column: &Column,
36553658
prefix: &str,
3656-
out: &mut AstPass<Pg>,
3659+
out: &mut AstPass<'_, 'b, Pg>,
36573660
) -> QueryResult<()> {
36583661
out.push_sql(" left join ");
36593662
out.push_sql(child_table.qualified_name.as_str());
@@ -3693,7 +3696,7 @@ impl<'a> SortKey<'a> {
36933696
out.push_sql(".");
36943697
out.push_identifier(BLOCK_RANGE_COLUMN)?;
36953698
out.push_sql(" @> ");
3696-
out.push_bind_param::<Integer, _>(&block)?;
3699+
out.push_bind_param::<Integer, _>(block)?;
36973700
out.push_sql(") ");
36983701

36993702
Ok(())
@@ -3855,7 +3858,7 @@ impl<'a> FilterQuery<'a> {
38553858
out.push_sql(table.qualified_name.as_str());
38563859
out.push_sql(" c");
38573860

3858-
self.sort_key.add_child(self.block, out)?;
3861+
self.sort_key.add_child(&self.block, out)?;
38593862

38603863
out.push_sql("\n where ");
38613864

@@ -3926,7 +3929,7 @@ impl<'a> FilterQuery<'a> {
39263929
out.push_sql("select c.*, p.id::text as ");
39273930
out.push_sql(&*PARENT_ID);
39283931
window.children(
3929-
ParentLimit::Ranked(&self.sort_key, &self.range),
3932+
&ParentLimit::Ranked(&self.sort_key, &self.range),
39303933
self.block,
39313934
&mut out,
39323935
)?;

0 commit comments

Comments
 (0)