A query language, over Go code, in Go!
This package is under heavy development, anything may change!
This is a golang sql driver, to interact with Go code. currently only select is possible, but the insert/update/delete is in todo list.
like any other sql driver in golang, just import the goql package in your code :
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/fzerorubigd/goql"
"github.com/fzerorubigd/goql/astdata"
)
func main() {
// open the net/http package
con, err := sql.Open("goql", "net/http")
if err != nil {
log.Fatal(err)
}
defer con.Close()
rows, err := con.Query("SELECT name, receiver, def FROM funcs")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var (
name string
rec sql.NullString
def astdata.Definition
)
rows.Scan(&name, &rec, &def)
if rec.Valid {
name = rec.String + "." + name
}
fmt.Printf("\nfunc %s , definition : %s", name, def.String())
}
}
Also there is an example command line is available for more advanced usage in cmd/goql
by running go get -u github.com/fzerorubigd/goql/...
the binary is available in your GOBIN
directory. you can run query against any installed package in your GOPATH
via this tool.
List of supported tables and fields are available in docs/table
there is one special type called definition
. this type is printed as string, but one can use functions to handle special queries. list of supported functions are available at docs/functions
also its possible to add new tables/fields/functions using plugins. an example plugin is available at plugin/goqlimport
currently only supported query is select
, with where
,order
and limit
some example query :
select * from files where the docs is not null
select * from funcs where def = 'func()' and exported
select * from consts order by name desc limit 10, 10
select * from vars where is_struct(def) and name like 's%'
select * from types where is_map(def) and map_key(def) = 'string'
select * from imports where canonical = 'ctx'
- Write (more) documentation
- UPDATE/INSERT/DELETE support (Yes, code generation with sql :) )