GithubHelp home page GithubHelp logo

qb's Introduction

qb - the database toolkit for go

Build Status Coverage Status License (LGPL version 2.1) Go Report Card GoDoc

This project is currently pre 1. More documentation will be coming soon. Although the tests coverage are high, currently, it is not recommended to use it in production. It can currently crash especially in concurrency.

About qb

qb is a database toolkit for easier db usage in go. It is inspired from python's most favorite orm sqlalchemy. qb is an orm as well as a query builder. It is quite modular in case of using just expression api and query building stuff.

Features

  • Support for postgres, mysql & sqlite
  • Simplistic query builder with no real magic
  • Struct to table ddl mapper where initial table migrations can happen
  • Expression builder which can be built almost any sql statements
  • Transactional session api that auto map structs to queries
  • Foreign Key definitions of structs using tags
  • Relationships (soon..)

Quick Start

package main

import (
	"fmt"
	"github.com/aacanakin/qb"
	"github.com/nu7hatch/gouuid"
)

type User struct {
	ID       string `qb:"type:uuid; constraints:primary_key"`
	Email    string `qb:"constraints:unique, notnull"`
	FullName string `qb:"constraints:notnull"`
	Password string `qb:"constraints:notnull"`
	Bio      string `qb:"type:text; constraints:null"`
}

func main() {

	db, err := qb.New("postgres", "user=postgres dbname=qb_test sslmode=disable")
	if err != nil {
		panic(err)
	}

	// add table to metadata
	db.Metadata().Add(User{})

	// create all tables registered to metadata
	db.Metadata().CreateAll()

	userID, _ := uuid.NewV4()
	user := &User{
		ID:       userID.String(),
		Email:    "[email protected]",
		FullName: "Robert De Niro",
		Password: "rdn",
	}

	db.Add(user)
	err = db.Commit() // insert user

	var robert User
	db.Find(&User{ID: userID.String()}).First(&robert)

	fmt.Printf("%v\n", robert)

}

qb's People

Contributors

aacanakin avatar

Watchers

 avatar

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.