not (an ORM) is an Open Source Prisma alternative for Go, featuring:
- 🪄 No DSLs, no tags, no magic
- 🚀 Prisma-like database APIs
- 🐘 Postgres support (other databases coming soon)
- 🪫 Batteries not included
⚠️ Please keep in mind that not is still under active development and therefore full backward compatibility is not guaranteed before reaching v1.0.0.
Overview
Installation
$ go install github.com/rickymarcon/not/cmd/not@latest
This will install the not binary to your $GOPATH/bin directory.
Usage
Usage: not [OPTIONS] DRIVER COMMAND [ARGUMENTS]
Examples:
not postgres generate "postgres://user:pass@localhost:5432/dbname"
not postgres sql-generate "path/to/sql/files"
Options:
-h, --help print help
-o, --out string the output directory for the generated code (default "not")
Commands:
generate Generate a Go client for the database schema
sql-generate Generate a Go client using a temporary database with migrated SQL files
Generate from running DB
$ not postgres generate "postgres://user:pass@localhost:5432/dbname"
This will generate a Go client for the database schema.
Generate from SQL
ℹ️ This command uses testcontainers-go and therefore requires a Docker-API compatible container runtime to be installed on your machine.
$ not postgres sql-generate "path/to/sql/files"
This command spins up a temporary Go container with the specified driver, creates a temporary database, migrates the SQL files from the specified directory, and then generates the SDK based on that temporary database instance before closing.
Example SDK Usage
package main
import (
"yourpackage/not" // generated not package
)
func main() {
dsn := "postgres://username:password@localhost/dbname?sslmode=disable"
c, err := not.NewClient("postgres", dsn)
if err != nil {
log.Fatalf("failed to connect to the database: %v", err)
}
// Use the generated client to perform database operations...
}
Create
Insert a new record into a table.
newProduct := ¬.Product{
Name: "Sample Product",
Price: 9.99,
}
product, err := c.Product.Create(ctx, ¬.CreateOptions{
Data: newProduct,
})
Read
FindUnique query lets you retrieve a single database record:
var id := "1"
product, err := c.Product.FindUnique(ctx,
¬.ProductOptions{
Where: ¬.ProductWhereInput{
ID: &id,
},
})
FindMany query lets you retrieve multiple database records:
price := 99
products, err := c.Product.FindMany(ctx,
¬.ProductOptions{
Where: ¬.ProductWhereInput{
Price: &price,
},
})
Update
Update a single record:
newProduct := *p
newProduct.Name = "newProduct"
updatedProduct, err = c.Product.Update(ctx,
¬.ProductUpdateParams{
Where: ¬.ProductWhereInput{
ID: &product.ID,
},
Data: &newProduct,
})
Delete
Delete one or many records:
err = c.Product.Delete(ctx,
¬.ProductOptions{
Where: ¬.ProductWhereInput{
ID: &id,
},
})
Acknowledgements
not is inspired by Prisma and entgo.io.
License
not is released under the MIT License.