Skip to content

Commit

Permalink
readme: Update diagram to be mermaid, use language specifiers for sni…
Browse files Browse the repository at this point in the history
…ppets
  • Loading branch information
echarrod committed Aug 21, 2024
1 parent e459dea commit 45d90f2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ Shift provides the SQL persistence layer for a simple "finite state machine" dom

A Shift state machine is composed of an initial state followed by multiple subsequent states linked by allowed transitions, i.e., a rooted directed graph.

```mermaid
stateDiagram-v2
direction LR
[*] --> Created
Created --> Pending
Pending --> Failed
Pending --> Completed
Failed --> Pending
Completed --> [*]
```
┌───────────┐
▽ │
CREATED ──▷ PENDING ─┬─▷ FAILED
└─▷ COMPLETED
```

Each state has an associated struct defining the data modified when entering the state.

```
Expand Down Expand Up @@ -67,7 +68,7 @@ Differences of ArcFSM from FSM:
# Usage

The above state machine is defined by:
```
```go
events := rsql.NewEventsTableInt("events")
fsm := shift.NewFSM(events)
Insert(CREATED, create{}, PENDING).
Expand All @@ -83,14 +84,13 @@ Shift requires the state structs to implement `Inserter` or `Updater` interfaces

A command `shiftgen` is provided that generates SQL boilerplate to implement these interfaces.

```
```go
//go:generate shiftgen -inserter=create -updaters=pending,failed,completed -table=mysql_table_name
```

The `fsm` instance is then used by the business logic to drive the state machine.

```
```go
// Insert a new domain model (in the CREATED) state.
id, err := fsm.Insert(ctx, dbc, create{"user123",TypeDefault})

Expand Down

0 comments on commit 45d90f2

Please sign in to comment.