Skip to content

Commit

Permalink
Fix documentation issue, bump version to 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Einliterflasche committed Aug 29, 2023
1 parent efdf655 commit 08d2b34
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pg-worm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pg-worm"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
authors = ["Einliterflasche <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
27 changes: 13 additions & 14 deletions pg-worm/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# `pg-worm`
# `pg-worm``
[![Latest Version](https://img.shields.io/crates/v/pg-worm.svg)](https://crates.io/crates/pg-worm)
![GitHub Actions Testing](https://github.com/Einliterflasche/pg-worm/actions/workflows/rust.yml/badge.svg)
[![docs](https://docs.rs/pg-worm/badge.svg)](https://docs.rs/pg-worm)
[![license](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

### *P*ost*g*reSQL's *W*orst *ORM*
`pg-worm` is a straightforward, fully typed, async ORM and Query Builder for PostgreSQL.
`pg-worm`` is a straightforward, fully typed, async ORM and Query Builder for PostgreSQL.
Well, at least that's the goal.

## Why though?
## Features/Why `pg-worm`?

- Existing ORMs are not **`async`**, require you to write migrations or use a cli.
`pg-worm's explicit goal is to be **easy** and to require **no setup** beyond defining your types.
`pg-worm`'s explicit goal is to be **easy** and to require **no setup** beyond defining your types.

- `pg-worm also features **built-in pooling** and a **concise syntax**.
- `pg-worm` also features **built-in pooling** and a **concise syntax**.

- `pg-worm **doesn't get in your way** - easily include raw queries while still profiting off the other features.
- `pg-worm` **doesn't get in your way** - easily include raw queries while still profiting off the other features.

## Usage
This library is based on [`tokio_postgres`](https://docs.rs/tokio-postgres/0.7.8/tokio_postgres/index.html) and is intended to be used with [`tokio`](https://tokio.rs/).

Fortunately, using `pg-worm is very easy.
Fortunately, using `pg-worm` is very easy.

Simply derive the `Model` trait for your type, connect to your database
and you are ready to go!
Expand All @@ -44,14 +44,13 @@ struct Book {
struct Author {
#[column(primary_key, auto)]
id: i64,
name: String,
age: i64
name: String
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// First create a connection. This can be only done once.
Connection::to("postgres://postgres:postgres@localhost:5432").await?;
Connection::build("postgres://postgres:postgres@localhost:5432").connect()?;

// Then, create tables for your models.
// Use `try_create_table!` if you want to fail if a
Expand Down Expand Up @@ -105,8 +104,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
If you want to see more code examples, have a look at the [tests directory](https://github.com/Einliterflasche/pg-worm/tree/main/pg-worm/tests).

## Query Builders
As you can see above, `pg-worm allows you to build queries by chaining methods on so called 'builders'.
For each query type `pg-worm provides a respective builder (except for `INSERT` which is handled differently).
As you can see above, `pg-worm` allows you to build queries by chaining methods on so called 'builders'.
For each query type `pg-worm` provides a respective builder (except for `INSERT` which is handled differently).

These builders expose a set of methods for building queries. Here's a list of them:

Expand All @@ -121,7 +120,7 @@ Method | Description | Availability
`.where_()` can be used to easily include `WHERE` clauses in your queries.

This is done by passing a `Where` object which can be constructed by calling methods on the respective column.
`pg-worm automatically constructs a constant for each field
`pg-worm` automatically constructs a constant for each field
of your `Model`.

A practical example would look like this:
Expand Down Expand Up @@ -186,7 +185,7 @@ Alse see `.where_raw` on query builders by which you can pass a raw condition wi

## Transactions

`pg-worm also supports transactions. You can easily execute any query inside a `Transaction` and only commit when you are satisfied.
`pg-worm` also supports transactions. You can easily execute any query inside a `Transaction` and only commit when you are satisfied.

`Transaction`s are automatically rolled-back when dropped, unless they have been committed beforehand.

Expand Down
37 changes: 18 additions & 19 deletions pg-worm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/*!
# `pg-worm`
# `pg-worm``
[![Latest Version](https://img.shields.io/crates/v/pg-worm.svg)](https://crates.io/crates/pg-worm)
![GitHub Actions Testing](https://github.com/Einliterflasche/pg-worm/actions/workflows/rust.yml/badge.svg)
[![docs](https://docs.rs/pg-worm/badge.svg)](https://docs.rs/pg-worm)
[![license](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
### *P*ost*g*reSQL's *W*orst *ORM*
`pg-worm` is a straightforward, fully typed, async ORM and Query Builder for PostgreSQL.
`pg-worm`` is a straightforward, fully typed, async ORM and Query Builder for PostgreSQL.
Well, at least that's the goal.
## Features/Why `pg-worm?
## Features/Why `pg-worm`?
- Existing ORMs are not **`async`**, require you to write migrations or use a cli.
`pg-worm's explicit goal is to be **easy** and to require **no setup** beyond defining your types.
`pg-worm`'s explicit goal is to be **easy** and to require **no setup** beyond defining your types.
- `pg-worm also features **built-in pooling** and a **concise syntax**.
- `pg-worm` also features **built-in pooling** and a **concise syntax**.
- `pg-worm **doesn't get in your way** - easily include raw queries while still profiting off the other features.
- `pg-worm` **doesn't get in your way** - easily include raw queries while still profiting off the other features.
## Usage
This library is based on [`tokio_postgres`](https://docs.rs/tokio-postgres/0.7.8/tokio_postgres/index.html) and is intended to be used with [`tokio`](https://tokio.rs/).
Fortunately, using `pg-worm is very easy.
Fortunately, using `pg-worm` is very easy.
Simply derive the `Model` trait for your type, connect to your database
and you are ready to go!
Expand All @@ -37,22 +37,21 @@ struct Book {
// An auto-generated primary key
#[column(primary_key, auto)]
id: i64,
title: String
title: String,
author_id: i64
}
#[derive(Model)]
struct Author {
#[column(primary_key, auto)]
id: i64,
name: String,
age: i64
name: String
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// First create a connection. This can be only done once.
Connection::to("postgres://postgres:postgres@localhost:5432").await?;
Connection::build("postgres://postgres:postgres@localhost:5432").connect()?;
// Then, create tables for your models.
// Use `try_create_table!` if you want to fail if a
Expand Down Expand Up @@ -106,8 +105,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
If you want to see more code examples, have a look at the [tests directory](https://github.com/Einliterflasche/pg-worm/tree/main/pg-worm/tests).
## Query Builders
As you can see above, `pg-worm allows you to build queries by chaining methods on so called 'builders'.
For each query type `pg-worm provides a respective builder (except for `INSERT` which is handled differently).
As you can see above, `pg-worm` allows you to build queries by chaining methods on so called 'builders'.
For each query type `pg-worm` provides a respective builder (except for `INSERT` which is handled differently).
These builders expose a set of methods for building queries. Here's a list of them:
Expand All @@ -122,12 +121,12 @@ Method | Description | Availability
`.where_()` can be used to easily include `WHERE` clauses in your queries.
This is done by passing a `Where` object which can be constructed by calling methods on the respective column.
`pg-worm automatically constructs a constant for each field
`pg-worm` automatically constructs a constant for each field
of your `Model`.
A practical example would look like this:
```rust
```ignore
let where_: Where<'_> = MyModel::my_field.eq(&5);
```
Expand All @@ -146,7 +145,7 @@ Function | Description | Availability
You can also chain/modify these filters with standard boolean logic:
```rust
```ignore
Book::select()
.where_(!Book::id.eq(&1) & Book::id.gt(&3))
.await?;
Expand All @@ -170,7 +169,7 @@ Executing a query will always result in a `Result`.
Though these features are nice, they are not sufficient for all applications. This is why you can easily execute custom queries and still take advantage of automatic parsing, etc:
```rust
```ignore
// NOTE: You have to pass the exact type that PostgreSQL is
// expecting. Doing otherwise will result in a runtime error.
let king_books = Book::query(r#"
Expand All @@ -187,13 +186,13 @@ Alse see `.where_raw` on query builders by which you can pass a raw condition wi
## Transactions
`pg-worm also supports transactions. You can easily execute any query inside a `Transaction` and only commit when you are satisfied.
`pg-worm` also supports transactions. You can easily execute any query inside a `Transaction` and only commit when you are satisfied.
`Transaction`s are automatically rolled-back when dropped, unless they have been committed beforehand.
Here's an example:
```rust
```ignore
use pg_worm::prelude::*;
#[derive(Model)]
Expand Down

0 comments on commit 08d2b34

Please sign in to comment.