Coder Social home page Coder Social logo

endo's Introduction

Endo

๐Ÿšง WORK IN PROGRESS ๐Ÿšง

Endo generates CRUD functions (SQL) for your Go structs, in a bring-your-own-types manner. Here's how it works:

  • You write your models in Go structs using your types.
  • You run endogen to generate the CRUD functions (Get, GetAll, Create, Update, Patch, Delete) for those models.
  • You can use and extend the generated code.

An example model:

import "gopkg.in/guregu/null.v4"

type User struct {
	ID                int         `db:"id,primary"`
	Email             string      `db:"email"`
	FirstName         null.String `db:"first_name"`
	LastName          null.String `db:"last_name"`
	EmailVerified     bool        `db:"email_verified"`
	PasswordHash      null.String `db:"password_hash"`
	CreatedAt         time.Time   `db:"created_at"`
	UpdatedAt         time.Time   `db:"updated_at"`
}

Endo generates the following functions for the model:

GetUser(ctx context.Context, key int) (*User, error)
GetUserByField(ctx context.Context, field string, v interface{}) (*User, error)
GetUsers(ctx context.Context, po endo.PageOptions) ([]*User, error)
CreateUser(ctx context.Context, e User) (*User, error)
UpdateUser(ctx context.Context, key int, e User) (*User, error)
UpdateUserByField(ctx context.Context, field string, v interface{}, e User) (*User, error)
PatchUser(ctx context.Context, key int, p UserPatch) (*User, error)
PatchUserByField(ctx context.Context, field string, v interface{}, p UserPatch) (*User, error)
DeleteUser(ctx context.Context, key int) error
DeleteUserByField(ctx context.Context, field string, v interface{}) error

Checkout the examples directory for more.

Features

  • Basic CRUD functions (with SQL) based on Go structs. Supports all your types!
  • Additional functions when a primary key is used.
  • Patches using dynamic SQL.

    Endo has an simple builtin query generator endo.Builder, it's actually strings.Builder with a few additions.

  • Supports transactional contexts through endo.TxFunc.
  • Optional customization via comment parameters.
  • Extensible and reusable.

Why another library like x?

Although sqlx, sqlc and sqlboiler are great libraries with wide support by multiple communities, it always feels like some important features are missing like simple dynamic patching. Endo doesn't try to replace those libraries, it simply tries a different approach to cover the basic things. If you don't need dynamic patching or extensibility, you're better off with sqlc or sqlx. Endo tries to be as simple and boring as possible, yet extensible and easy-to-use, less is more.

Roadmap

  • Basic CRUD templates.
  • Supports PostgreSQL.
  • Dynamic patches using dynamic SQL generation with minimal overhead.
  • MySQL support.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.