gosqljson

A Go SQL to maps, arrays and JSON library.

  • 所有者: elgs/gosqljson
  • 平台:
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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"}]
}

主要指標

概覽
名稱與所有者elgs/gosqljson
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證Other
所有者活动
創建於2014-08-17 07:34:46
推送於2023-04-01 11:20:41
最后一次提交2023-04-01 04:20:35
發布數0
用户参与
星數62
關注者數6
派生數10
提交數66
已啟用問題?
問題數1
打開的問題數1
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?