Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbfh-dev/go-orm
Simple and reliable ORM for SQL databases
https://github.com/bbfh-dev/go-orm
golang orm sql
Last synced: 29 days ago
JSON representation
Simple and reliable ORM for SQL databases
- Host: GitHub
- URL: https://github.com/bbfh-dev/go-orm
- Owner: bbfh-dev
- License: gpl-3.0
- Created: 2024-10-01T09:25:47.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-01T12:10:44.000Z (about 2 months ago)
- Last Synced: 2024-10-02T07:41:15.594Z (about 1 month ago)
- Topics: golang, orm, sql
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go ORM
> [!IMPORTANT]
> This project is now archived. It was more of a fun experience developing this, for production it's better to use something like [GORM](https://gorm.io/index.html)Designed to be a simple and reliable ORM for SQL databases.
It doesn't perform any database altering operations unless given permission to. It's explicit in its actions and prints useful debug information using `slog.Debug`.
* [Features](#features)
* [Example](#example)# Features
- Automatically syncronize database table with Go struct (CREATE, ALTER, DROP);
- Query fields / entire tables with ease;
- Does not perform any operations unless ORM_MIGRATE=1 env is present;
- Explicit errors prefixed with the operation that caused them;
- Explicit logging using `slog` (With DEBUG messages per every SQL call)# Example
```go
// An example struct, every field must have "db" and "create" tags
type TestTable struct {
ExampleId int64 `db:"example_id" create:"INTEGER PRIMARY KEY"`
Name string `db:"name" create:"TEXT NOT NULL DEFAULT ''"`
Description string `db:"description" create:"TEXT NOT NULL DEFAULT ''"`
}// The only required method, returns the name of the table in SQL database
func (table TestTable) SQL() string {
return "test_table"
}func main() {
// In this example we use SQLite3
sqlDB, err := sqlx.Open("libsql", "file:/tmp/my.db")
if err != nil {
panic(err)
}// Create the Go-ORM database wrapper
db := orm.NewDB(sqlDB)
// Tell it what tables we have
db.Tables = []tables.Table{TestTable{}}// Ensure that SQL database is in-sync with our go struct
err = db.GenMigrations()
if err != nil {
panic(err)
}
}
```