Show HN: Gogress a simple SQL database in Go with WAL support

igomeza1 pts0 comments

GitHub - igomez10/gogress: A simple SQL database in go with WAL support · GitHub

/" data-turbo-transient="true" />

Skip to content

Search/

Sign in<br>Sign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

igomez10

gogress

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star

main

BranchesTags

Go to file

CodeOpen more actions menu

Latest commit

History<br>29 Commits<br>29 Commits

Folders and files<br>NameNameLast commit message<br>Last commit date<br>.github/workflows

.github/workflows

.vscode

.vscode

cli

cli

pkg

pkg

.gitignore

.gitignore

Makefile

Makefile

README.md

README.md

go.mod

go.mod

go.sum

go.sum

main.go

main.go

main_test.go

main_test.go

View all files

Repository files navigation

gogress

gogress is a lightweight Go-based file storage database with a simple write-ahead log (WAL) mechanism. It supports table creation, basic key-value operations, and crash recovery by replaying log files.

Example with CLI

# Start the CLI<br>gogress-cli list-tables<br>cars<br>new_table<br>users<br>default

# create a table<br>gogress-cli create-table products

# create a record<br>gogress-cli put products sku123 hammer

# get a record<br>gogress-cli get products sku123<br>hammer

# run a simple SQL query (experimental)<br>gogress-cli sql "select * from products"<br>sku123: hammer

# filter with a WHERE clause<br>gogress-cli sql "select * from products where id='sku123'"<br>sku123: hammer

Project Structure

Main Application

Root-level main.go launches the application.

Command-Line Interface (CLI)

The cli directory contains CLI-specific code and tests (cli/main.go, cli/main_test.go).

Database Implementation

The core database logic is implemented under the pkg/db folder:

db.NewDB: Initializes a new database instance.

db.Table: Provides methods like Put and Get to store and retrieve records.

Write-ahead logging and crash recovery is managed in db.BuildIndex.

Experimental SQL entrypoint db.SQL powering the sql CLI subcommand.

Tests

Unit tests cover various components:

Main application tests in main_test.go.

Database tests in pkg/db/db_test.go and pkg/db/table_test.go.

Getting Started

Prerequisites

Go (version 1.16 or later)

A Unix-like environment to support file system operations

Installation

Clone the repository and navigate to the project folder:

git clone https://github.com/igomez10/gogress.git<br>cd gogress

Build

Build the project using go build:

go build -o gogress-cli cli/main.go

Running Tests

Run all tests with:

go test ./...

Or test specific packages:

go test ./pkg/db

Usage

The database is initialized in db.NewDB and can be used to perform key-value operations. The CLI (located in the cli directory) currently supports commands such as listing tables (see TestListTables in cli/main_test.go).

Examples of operations include:

Put a Record:

Refer to db.Table.Put for adding a new record.

Get a Record:

See db.Table.Get for retrieving stored values.

SQL (experimental)

You can run a very small subset of SQL via the CLI or directly from Go. Currently supported:

SELECT with a FROM clause: select * from

Returns up to 10 records by default.

WHERE clause for equality filtering: select * from where = ''

Supports both spaced (col = 'val') and compact (col=val) syntax.

Ordering, projections, and joins are not supported yet.

CLI example:

gogress-cli sql "select * from products"

Programmatic example:

records, err := db.SQL("select * from products")<br>if err != nil {<br>// handle error<br>for _, r := range records {<br>fmt.Printf("%s: %s\n", r.Key, r.Value)

Storage and Recovery

Storage Files:

Data is stored in files under /tmp/gogress/ (as set in db.initializeStorage).

Crash Recovery:

A write-ahead log (WAL) is maintained and used to rebuild the in-memory index via db.BuildIndex.

CLI commands overview

Tables

Create: gogress-cli create-table

List: gogress-cli list-tables

Delete: gogress-cli delete-table

Data

Put: gogress-cli put

Get: gogress-cli get

Scan: gogress-cli scan [--limit N] [--offset N]

SQL (experimental): gogress-cli sql "select * from [where col='val']"

Contributing

Feel free to fork the project and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.

License

This project is provided without any warranty. See the LICENSE file

About<br>A simple SQL database in go with WAL support<br>Resources<br>Readme<br>Activity<br>Stars<br>1 star<br>Watchers<br>0 watching<br>Forks<br>0 forks<br>Report repository

Releases

Packages

Contributors

Languages

You can’t perform that action at this time.

gogress database from main table select

Related Articles