Skip to content

Commit

Permalink
fix: fix contract queries
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Feb 22, 2024
1 parent 030e762 commit 9a6ee1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/db/lib/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,18 @@ class Database {
return queryMany(allContractsQuery(), contractFromColumnMap);
}

/// Get a contract by id.
Future<Contract?> contractById(String id) async {
final query = contractByIdQuery(id);
return queryOne(query, contractFromColumnMap);
}

/// Get all contracts which are !accepted.
Future<Iterable<Contract>> unacceptedContracts() async {
return queryMany(unacceptedContractsQuery(), contractFromColumnMap);
}

/// Get all contracts which are !fullfilled and !expired.
Future<Iterable<Contract>> activeContracts() async {
return queryMany(activeContractsQuery(), contractFromColumnMap);
}
Expand Down
9 changes: 6 additions & 3 deletions packages/db/lib/src/contract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ Query contractByIdQuery(String id) {
);
}

/// Get all contracts which are !fulfilled and expiration date is in the future.
Query activeContractsQuery() {
return const Query(
"SELECT * FROM contract_ WHERE json->>'status' = 'active'",
return Query(
"SELECT * FROM contract_ WHERE json->>'fulfilled' = 'false' AND json->>'expiration' > @now",
parameters: {'now': DateTime.timestamp()},
);
}

/// Get all contracts which are !accepted.
Query unacceptedContractsQuery() {
return const Query(
"SELECT * FROM contract_ WHERE json->>'status' = 'unaccepted'",
"SELECT * FROM contract_ WHERE json->>'accepted' = 'false'",
);
}

Expand Down

0 comments on commit 9a6ee1b

Please sign in to comment.