https://github.com/octu0/wal
simple/small Write Ahead Log
https://github.com/octu0/wal
wal write-ahead-log
Last synced: 11 months ago
JSON representation
simple/small Write Ahead Log
- Host: GitHub
- URL: https://github.com/octu0/wal
- Owner: octu0
- License: mit
- Created: 2023-02-12T11:27:53.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-06T12:41:07.000Z (about 3 years ago)
- Last Synced: 2024-12-30T03:43:21.015Z (over 1 year ago)
- Topics: wal, write-ahead-log
- Language: Go
- Homepage: https://pkg.go.dev/github.com/octu0/wal
- Size: 57.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `wal`
[](https://github.com/octu0/wal/blob/master/LICENSE)
[](https://godoc.org/github.com/octu0/wal)
[](https://goreportcard.com/report/github.com/octu0/wal)
[](https://github.com/octu0/wal/releases)
**simple/small** write ahead log.
## Installation
```
$ go get github.com/octu0/wal
```
## Example
```go
import "github.com/octu0/wal"
func main() {
log, err := Open("/path/to/dir", wal.WithSync(true))
if err != nil {
panic(err)
}
defer log.Close()
i1, err := log.Write([]byte("data1"))
i2, err := log.Write([]byte("data2"))
err := log.WriteAt(Index(100), []byte("data3"))
data1, _ := log.Read(i1)
println(string(data1)) // => "data1"
data3, _ := log.Read(Index(100))
println(string(data3)) // => "data3"
// delete logs on memory
if err := log.Delete(i1, i2); err != nil {
panic(err)
}
// compaction of deleted logs to free disk space
if err := log.Compact(); err != nil {
panic(err)
}
}
```
# License
MIT, see LICENSE file for details.