mysqlann

package module
v0.0.0-...-4a0a4e2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

README

MiTo Team MysqlAnn

Go Report Card GoDoc Sourcegraph

MySQL query builder for Golang

WARNING: Not ready for production yet

  • Building SQL queries
  • Executing SQL queries
package main

import (
  "fmt"
  "github.com/mitoteam/mysqlann"
  "database/sql"
)

func main(){
	//creating query
	q := mysqlann.Select("mt_user", "u", "Role", "UserName").
		Where("ID", 67).
		Limit(1)
	fmt.Println("SQL:")
	fmt.Println(q.Sql())

	//initialize connection pool
	db, _ := sql.Open("mysql", "user:password@tcp(webdev4.test)/test") //use your own DSN
	mysqlann.SetDB(db)

	//run query
	row_values, _ := q.QueryRowMap()
	fmt.Println("Result: ", row_values)
}

Will produce

SQL:
SELECT `u`.`Role` AS `Role`,
       `u`.`UserName` AS `UserName`
FROM `mt_user` u
WHERE (ID = 67)
LIMIT 1

Result:  map[Role:admin UserName:TestUser]

Documentation

Index

Constants

View Source
const (
	OR  = 1
	AND = 2
)

glue types

Variables

This section is empty.

Functions

func And

func And() *queryCondition

func AnythingToSql

func AnythingToSql(value Anything) string

func AnythingToString

func AnythingToString(value Anything) string

func Delete

func Delete(table_name string) *deleteQuery

func Insert

func Insert(table_name string) *insertQuery

func Or

func Or() *queryCondition

func Select

func Select(table_name string, args ...string) *selectQuery

func SetDB

func SetDB(new_db *sql.DB)

func Update

func Update(table_name string) *updateQuery

Types

type Anything

type Anything interface{}

region Anything

type ConditionGlueOperator

type ConditionGlueOperator int

type Query

type Query interface {
	Sql() string
}

region Query interface

Jump to

Keyboard shortcuts

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