All Projects → Fs02 → Grimoire

Fs02 / Grimoire

Licence: mit
Database access layer for golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Grimoire

Sqlboiler
Generate a Go ORM tailored to your database schema.
Stars: ✭ 4,497 (+2878.15%)
Mutual labels:  orm, database, mysql, postgres, sqlite3
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+2465.56%)
Mutual labels:  orm, database, mysql, sqlite3
Wetland
A Node.js ORM, mapping-based. Works with MySQL, PostgreSQL, SQLite and more.
Stars: ✭ 261 (+72.85%)
Mutual labels:  orm, database, mysql, postgres
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+739.07%)
Mutual labels:  database, mysql, postgres, sqlite3
Cmd
Command line tools for database operation written by Go, moved to https://gitea.com/xorm/cmd
Stars: ✭ 154 (+1.99%)
Mutual labels:  orm, mysql, postgres, sqlite3
Architect
A set of tools which enhances ORMs written in Python with more features
Stars: ✭ 320 (+111.92%)
Mutual labels:  orm, database, mysql, postgres
Ebean
Ebean ORM
Stars: ✭ 1,172 (+676.16%)
Mutual labels:  orm, database, mysql, postgres
Qb
The database toolkit for go
Stars: ✭ 524 (+247.02%)
Mutual labels:  orm, database, mysql, sqlite3
Gnorm
A database-first code generator for any language
Stars: ✭ 415 (+174.83%)
Mutual labels:  orm, database, mysql, postgres
Crecto
Database wrapper and ORM for Crystal, inspired by Ecto
Stars: ✭ 325 (+115.23%)
Mutual labels:  orm, database, mysql, postgres
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (+229.8%)
Mutual labels:  orm, database, mysql, sqlite3
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+11931.79%)
Mutual labels:  orm, database, mysql, postgres
Go Kallax
Kallax is a PostgreSQL typesafe ORM for the Go language.
Stars: ✭ 853 (+464.9%)
Mutual labels:  orm, database, postgres
Goloquent
This repo no longer under maintenance, please go to https://github.com/si3nloong/sqlike
Stars: ✭ 16 (-89.4%)
Mutual labels:  orm, database, mysql
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+551.66%)
Mutual labels:  database, mysql, postgres
Gormt
database to golang struct
Stars: ✭ 1,063 (+603.97%)
Mutual labels:  orm, database, mysql
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+4180.79%)
Mutual labels:  orm, mysql, postgres
Hunt Entity
An object-relational mapping (ORM) framework for D language (Similar to JPA / Doctrine), support PostgreSQL and MySQL.
Stars: ✭ 51 (-66.23%)
Mutual labels:  orm, database, mysql
East
node.js database migration tool
Stars: ✭ 53 (-64.9%)
Mutual labels:  database, mysql, postgres
Bookshelf
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Stars: ✭ 6,252 (+4040.4%)
Mutual labels:  orm, database, mysql

grimoire

GoDoc Build Status Go Report Card Maintainability Test Coverage FOSSA Status

⚠️ Grimoire V2 is available as REL and Changeset package.

Grimoire is a database access layer inspired by Ecto. It features a flexible query API and built-in validation. It currently supports MySQL, PostgreSQL, and SQLite3 but a custom adapter can be implemented easily using the Adapter interface.

Features:

  • Query Builder
  • Association Preloading
  • Struct style create and update
  • Changeset Style create and update
  • Builtin validation using changeset
  • Multi adapter support
  • Logger

Motivation

Common go ORM accepts struct as a value for modifying records which has a problem of unable to differentiate between an empty, nil, or undefined value. It's a tricky problem especially when you want to have an endpoint that supports partial updates. Grimoire attempts to solve that problem by integrating Changeset system inspired from Elixir's Ecto. Changeset is a form like entity which allows us to not only solve that problem but also help us with casting, validations, and constraints check.

Install

go get github.com/Fs02/grimoire

Quick Start

package main

import (
	"time"

	"github.com/Fs02/grimoire"
	"github.com/Fs02/grimoire/adapter/mysql"
	"github.com/Fs02/grimoire/changeset"
	"github.com/Fs02/grimoire/params"
)

type Product struct {
	ID        int
	Name      string
	Price     int
	CreatedAt time.Time
	UpdatedAt time.Time
}

// ChangeProduct prepares data before database operation.
// Such as casting value to appropriate types and perform validations.
func ChangeProduct(product interface{}, params params.Params) *changeset.Changeset {
	ch := changeset.Cast(product, params, []string{"name", "price"})
	changeset.ValidateRequired(ch, []string{"name", "price"})
	changeset.ValidateMin(ch, "price", 100)
	return ch
}

func main() {
	// initialize mysql adapter.
	adapter, err := mysql.Open("[email protected](127.0.0.1:3306)/db?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}
	defer adapter.Close()

	// initialize grimoire's repo.
	repo := grimoire.New(adapter)

	var product Product

	// Inserting Products.
	// Changeset is used when creating or updating your data.
	ch := ChangeProduct(product, params.Map{
		"name":  "shampoo",
		"price": 1000,
	})

	if ch.Error() != nil {
		// handle error
	}

	// Changeset can also be created directly from json string.
	jsonch := ChangeProduct(product, params.ParseJSON(`{
		"name":  "soap",
		"price": 2000,
	}`))

	// Create products with changeset and return the result to &product,
	if err = repo.From("products").Insert(&product, ch); err != nil {
		// handle error
	}

	// or panic when insertion pailed
	repo.From("products").MustInsert(&product, jsonch)

	// Querying Products.
	// Find a product with id 1.
	repo.From("products").Find(1).MustOne(&product)

	// Updating Products.
	// Update products with id=1.
	repo.From("products").Find(1).MustUpdate(&product, ch)

	// Deleting Products.
	// Delete Product with id=1.
	repo.From("products").Find(1).MustDelete()
}

Examples

Documentation

Guides: https://fs02.github.io/grimoire

API Documentation: https://godoc.org/github.com/Fs02/grimoire

License

Released under the MIT License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].