Skip to content

Commit

Permalink
doc: supported sqlite drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Jun 10, 2024
1 parent 66283fb commit 92b977d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/install-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ go get github.com/nalgeon/redka

You'll also need an SQLite driver. Use one of the following:

- `github.com/mattn/go-sqlite3` (CGO)
- `github.com/mattn/go-sqlite3` (CGO, fastest)
- `github.com/ncruces/go-sqlite3` (pure Go, WASM)
- `github.com/tursodatabase/go-libsql` (CGO)
- `modernc.org/sqlite` (pure Go)

Install a driver with `go get` like this:
Expand Down
25 changes: 21 additions & 4 deletions docs/usage-module.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Using Redka as a Go module

If you are using Go, Redka is available as a module without the need to start a separate server.

See the [package documentation](https://pkg.go.dev/github.com/nalgeon/redka) for API reference.

## Opening the database

The primary object in Redka is the `DB`. To open or create your database, use the `redka.Open()` function:

```go
Expand All @@ -24,7 +30,7 @@ func main() {
}
```

Don't forget to import the driver (here I use `github.com/mattn/go-sqlite3`). Using `modernc.org/sqlite` is slightly different, see [example/modernc/main.go](example/modernc/main.go) for details.
Don't forget to import the driver (here I use `github.com/mattn/go-sqlite3`). See the list of the supported drivers below.

To open an in-memory database that doesn't persist to disk, use the following path:

Expand All @@ -33,6 +39,8 @@ To open an in-memory database that doesn't persist to disk, use the following pa
redka.Open("file:/data.db?vfs=memdb")
```

## Running commands

After opening the database, call `redka.DB` methods to run individual commands:

```go
Expand All @@ -51,7 +59,9 @@ count count=2 err=<nil>
get name="alice" err=<nil>
```

See the full example in [example/simple/main.go](example/simple/main.go).
See the full example in [example/simple/main.go](../example/simple/main.go).

## Transactions

Use transactions to batch commands. There are `View` (read-only transaction) and `Update` (writable transaction) methods for this:

Expand All @@ -78,6 +88,13 @@ slog.Info("updated", "count", updCount, "err", err)
updated count=2 err=<nil>
```

See the full example in [example/tx/main.go](example/tx/main.go).
See the full example in [example/tx/main.go](../example/tx/main.go).

See the [package documentation](https://pkg.go.dev/github.com/nalgeon/redka) for API reference.
## Supported drivers

Redka supports the following SQLite drivers:

- `github.com/mattn/go-sqlite3` ([example](../example/simple/main.go))
- `github.com/ncruces/go-sqlite3` ([example](../example/ncruces/main.go))
- `github.com/tursodatabase/go-libsql` ([example](../example/libsql/main.go))
- `modernc.org/sqlite` ([example](../example/modernc/main.go))

0 comments on commit 92b977d

Please sign in to comment.