Skip to content

Commit 2a5a3bd

Browse files
authored
Update README with a few tweaks and some new content from docs (#8)
Updates the README with some additions and changes that fell out of writing the documentation page for River in Ruby. Specifically there are new sections for inserting in a transaction and RBS + type checking.
1 parent 8323f78 commit 2a5a3bd

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

docs/README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ An insert-only Ruby client for [River](https://github.com/riverqueue/river) pack
44

55
## Basic usage
66

7-
`Gemfile` should contain the core gem and a driver like [`rubyqueue-sequel`](https://github.com/riverqueue/riverqueue-ruby/drivers/riverqueue-sequel) (see [drivers](#drivers)):
7+
Your project's `Gemfile` should contain the `riverqueue` gem and a driver like [`riverqueue-sequel`](https://github.com/riverqueue/riverqueue-ruby/drivers/riverqueue-sequel) (see [drivers](#drivers)):
88

9-
``` ruby
9+
```ruby
1010
gem "riverqueue"
1111
gem "riverqueue-sequel"
1212
```
@@ -44,7 +44,7 @@ Job args should:
4444

4545
They may also respond to `#insert_opts` with an instance of `InsertOpts` to define insertion options that'll be used for all jobs of the kind.
4646

47-
### Insertion options
47+
## Insertion options
4848

4949
Inserts take an `insert_opts` parameter to customize features of the inserted job:
5050

@@ -60,17 +60,7 @@ insert_res = client.insert(
6060
)
6161
```
6262

63-
### Inserting with a Ruby hash
64-
65-
`JobArgsHash` can be used to insert with a kind and JSON hash so that it's not necessary to define a class:
66-
67-
```ruby
68-
insert_res = client.insert(River::JobArgsHash.new("hash_kind", {
69-
job_num: 1
70-
}))
71-
```
72-
73-
### Bulk inserting jobs
63+
## Inserting jobs in bulk
7464

7565
Use `#insert_many` to bulk insert jobs as a single operation for improved efficiency:
7666

@@ -90,16 +80,48 @@ num_inserted = client.insert_many([
9080
])
9181
```
9282

83+
## Inserting in a transaction
84+
85+
No extra code is needed to insert jobs from inside a transaction. Just make sure that one is open from your ORM of choice, call the normal `#insert` or `#insert_many` methods, and insertions will take part in it.
86+
87+
```ruby
88+
ActiveRecord::Base.transaction do
89+
client.insert(SimpleArgs.new(strings: ["whale", "tiger", "bear"]))
90+
end
91+
```
92+
93+
```ruby
94+
DB.transaction do
95+
client.insert(SimpleArgs.new(strings: ["whale", "tiger", "bear"]))
96+
end
97+
```
98+
99+
## Inserting with a Ruby hash
100+
101+
`JobArgsHash` can be used to insert with a kind and JSON hash so that it's not necessary to define a class:
102+
103+
```ruby
104+
insert_res = client.insert(River::JobArgsHash.new("hash_kind", {
105+
job_num: 1
106+
}))
107+
```
108+
109+
## RBS and type checking
110+
111+
The gem [bundles RBS files](https://github.com/riverqueue/riverqueue-ruby/tree/master/sig) containing type annotations for its API to support type checking in Ruby through a tool like [Sorbet](https://sorbet.org/) or [Steep](https://github.com/soutaro/steep).
112+
93113
## Drivers
94114

95115
### ActiveRecord
96116

97-
``` ruby
117+
Use River with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html) by putting the `riverqueue-activerecord` driver in your `Gemfile`:
118+
119+
```ruby
98120
gem "riverqueue"
99121
gem "riverqueue-activerecord"
100122
```
101123

102-
Initialize driver and client:
124+
Then initialize driver and client:
103125

104126
```ruby
105127
ActiveRecord::Base.establish_connection("postgres://...")
@@ -108,12 +130,14 @@ client = River::Client.new(River::Driver::ActiveRecord.new)
108130

109131
### Sequel
110132

111-
``` ruby
133+
Use River with [Sequel](https://github.com/jeremyevans/sequel) by putting the `riverqueue-sequel` driver in your `Gemfile`:
134+
135+
```ruby
112136
gem "riverqueue"
113137
gem "riverqueue-sequel"
114138
```
115139

116-
Initialize driver and client:
140+
Then initialize driver and client:
117141

118142
```ruby
119143
DB = Sequel.connect("postgres://...")

0 commit comments

Comments
 (0)