Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implements a proof-of-concept SQL query builder. Currently only supports basic
SELECT
statements with a few conditionals, and uses the sea-query crate to compose and generate SQL for now (can be replaced later once the top-level API is finalised. since it's mostly opaque).This attempts to match the syntax from #4 (comment).
Example
The filters could also be combined into one using
&
instead of multiplefilter
s.fetch
function is provided behind thepostgres
flag to execute the query using the postgres crate:Just an example, other functions and feature flags could be added for different runtimes.
E.g. trying to compare a string to an integer will throw a compilation error:
TODOFuture Workjoin
.ON
clauses based on foreign keys for joins.join
clauses at compile-time to tables with foreign keys.SELECT *
for all columns.AccountsFields
,AccountsIden
,impl Table for Accounts
, etc.)?eq
on a BOOLEAN column only allows bools etc.)eq
,ne
,like
, etc.) .sea-query
?Problems
The big problem currently is being unable to restrict which tables can join each other at compile time, due to how the
Sources
trait is set up to operate on tuples of tables.E.g.
since trying to implement the same for B causes a "conflicting trait implementation" compilation error.
This restriction can be implemented quite easily at runtime, however.
Type of change
Enhancement (a non-breaking change which adds functionality)
How the change has been tested
Added unit tests. See the README.md for instructions.