1
0
mirror of https://github.com/fumiama/terasu-cloudflared.git synced 2026-06-16 00:15:24 +08:00

STOR-519: Add db-connect, a SQL over HTTPS server

This commit is contained in:
Ashcon Partovi
2019-08-20 13:13:29 -05:00
parent 28f6c2ed7c
commit 5da2109811
410 changed files with 362649 additions and 666 deletions

View File

@@ -1,56 +0,0 @@
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
```
```go
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"}]
}
```