not

module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2023 License: MIT

README

not - open source prisma alternative for go

build Latest releases Go package documentation

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 := &not.Product{
  Name: "Sample Product",
  Price: 9.99,
}
product, err := c.Product.Create(ctx, &not.CreateOptions{
  Data: newProduct,
})
Read

FindUnique query lets you retrieve a single database record:

var id := "1"
product, err := c.Product.FindUnique(ctx,
  &not.ProductOptions{
    Where: &not.ProductWhereInput{
      ID: &id,
    },
  })

FindMany query lets you retrieve multiple database records:

price := 99
products, err := c.Product.FindMany(ctx,
  &not.ProductOptions{
    Where: &not.ProductWhereInput{
      Price: &price,
    },
  })
Update

Update a single record:

newProduct := *p
newProduct.Name = "newProduct"
updatedProduct, err = c.Product.Update(ctx,
  &not.ProductUpdateParams{
    Where: &not.ProductWhereInput{
      ID: &product.ID,
    },
    Data: &newProduct,
  })
Delete

Delete one or many records:

err = c.Product.Delete(ctx,
  &not.ProductOptions{
    Where: &not.ProductWhereInput{
      ID: &id,
    },
  })

Acknowledgements

not is inspired by Prisma and entgo.io.

License

not is released under the MIT License.

Directories

Path Synopsis
cmd
not command
internal
gen
This version is based on the original https://github.com/ent/ent/blob/master/entc/gen/func.go, which is a modified version of code from ent/ent
This version is based on the original https://github.com/ent/ent/blob/master/entc/gen/func.go, which is a modified version of code from ent/ent

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL