gosqljson

A Go SQL to maps, arrays and JSON library.

  • Owner: elgs/gosqljson
  • Platform:
  • License:: Other
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

gosqljson

A Go SQL to JSON library.

#Installation
go get -u github.com/elgs/gosqljson

Sample code

Data in the table:

ID	NAME

0	Alicia
1	Brian
2	Chloe
4	Bianca
5	Leo
6	Joy
7	Sam
8	Elgs
package main

import (
	"database/sql"
	"fmt"
	"github.com/elgs/gosqljson"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	ds := "username:password@tcp(host:3306)/db"
	db, err := sql.Open("mysql", ds)

	if err != nil {
		fmt.Println("sql.Open:", err)
		return
	}

	theCase := "lower" // "lower", "upper", "camel" or the orignal case if this is anything other than these three

	// headers []string, data [][]string, error
	headers, data, _ := gosqljson.QueryDbToArray(db, theCase, "SELECT ID,NAME FROM t LIMIT ?,?", 0, 3)
	fmt.Println(headers)
	// ["id","name"]
	fmt.Println(data)
	// [["0","Alicia"],["1","Brian"],["2","Chloe"]]

	// data []map[string]string, error
	data, _ := gosqljson.QueryDbToMap(db, theCase, "SELECT ID,NAME FROM t LIMIT ?,?", 0, 3)
	fmt.Println(data)
	// [{"id":"0","name":"Alicia"},{"id":"1","name":"Brian"},{"id":"2","name":"Chloe"}]
}

Main metrics

Overview
Name With Ownerelgs/gosqljson
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:Other
所有者活动
Created At2014-08-17 07:34:46
Pushed At2023-04-01 11:20:41
Last Commit At2023-04-01 04:20:35
Release Count0
用户参与
Stargazers Count62
Watchers Count6
Fork Count10
Commits Count66
Has Issues Enabled
Issues Count1
Issue Open Count1
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private