pg-worm
PostgreSQL's Worst ORM
pg-worm is an opiniated, straightforward, async ORM for PostgreSQL servers.
Well, at least that's the goal.
This library is based on tokio_postgres
and is intended to be used with tokio.
Usage
Fortunately, using this library is very easy.
Just derive the Model trait for your type, connect to your database
and you are ready to go!
Here's a quick example:
use ;
// Postgres doesn't allow tables named `user`
async
Filters
Filters can be used to easily include WHERE clauses in your queries.
They can be constructed by calling functions of the respective column.
pg_worm automatically constructs a Column constant for each field
of your Model.
A practical example would look like this:
select
Currently the following filter functions are supported:
Filter::all()- doesn't check anythingeq(T)- checks whether the column value is equal to somethingneq(T)- checks whether the column value is not equal to somethingone_of(Vec<T>)- checks whether the vector contains the column value.none_of(Vec<T>)- checks whether the vector does not contain the column value.
You can also do filter logic using & and |: MyModel::my_field.eq(5) & MyModel::other_field.neq("Foo").
This works as you expect logical OR and AND to work.
Please notice that, at this point, custom priorization via parantheses
is not possible.
Opiniatedness
As mentioned before, pg_worm is opiniated in a number of ways.
These include:
-
panics. For the sake of conveniencepg_wormonly returns aResultwhen inserting data, since in that case Postgres might reject the data because of some constraint.This means that should something go wrong, like:
- the connection to the database collapsed,
pg_wormis unable to parse Postgres' response,- ...
the program will panic.
-
ease of use. The goal of
pg_wormis not to become an enterprise solution. If adding an option means infringing the ease of use then it will likely not be added.