Skip to content

Commit b76563b

Browse files
committed
update docs
1 parent 35a0729 commit b76563b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

GUIDE.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Production versions:
2020

2121
+ sqlc: v2.3.0-wicked-fork
2222
+ dcache: v0.3.0 (Note: redis/v8 users please use v0.1.4)
23-
+ wgpx: v0.3.0
23+
+ wgpx: v0.3.1
2424

2525
# Sqlc (this wicked fork)
2626

@@ -363,6 +363,35 @@ The best practice is to cache frequently queried objects, especially
363363
books, because it is hard for us to know if we should invalidate the cache of that list when we are updating
364364
information of some books, (unless you do some fancy bloom-filter stuff..).
365365

366+
#### Use Read Replica
367+
368+
We support heterogeneous database replicas, meaning that you can not only use physical replia that is exactly the same as
369+
the primary instance, but also logical replicas that may have different schema, like additional materialzied views, plugins,
370+
or only some part of the table.
371+
372+
Replicas are managed by the wpgx pool object. We enforce that read replicas are "read-only" on the SQL level.
373+
374+
Example:
375+
376+
```go
377+
replicaName := wpgx.ReplicaName("R1")
378+
r1, _ := suite.Pool.WQuerier(&replicaName)
379+
cond := "b%"
380+
rst, err := suite.usecase.books.UseReplica(r1).GetBookBySpec(ctx, books.GetBookBySpecParams{
381+
Name: &cond,
382+
})
383+
```
384+
385+
To setup managed read replica, you will configure them in the environment variables, like:
386+
387+
```
388+
POSTGRES_REPLICAPREFIXES=R1,R2
389+
R1_NAME=R1
390+
R1_HOST=localhost
391+
R1_PORT=5433
392+
...
393+
```
394+
366395
#### Timeout
367396

368397
Because setting timeout for queries is such an important practice, starting from v2.2.0, we make this a mandatory option.
@@ -389,6 +418,8 @@ The benefits of adding timeout to queries are:
389418

390419
When we mutate the state of table, we should proactively invalidate some cache values.
391420

421+
TBD: How the invalidate option support this feature and how it works in Transaction.
422+
392423
#### Best practices
393424

394425
+ When storing time in DB, **always** use `timestamptz`, the date type with timezone and

0 commit comments

Comments
 (0)