goql

A golang source code scanner, this time in sql :)

Github stars Tracking Chart

GoQL

A query language, over Go code, in Go!

Build Status
Coverage Status
GoDoc
Go Report Card

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.

Usage

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'

Demo

asciicast

TODO

  • Write (more) documentation
  • UPDATE/INSERT/DELETE support (Yes, code generation with sql :) )

Main metrics

Overview
Name With Ownerfzerorubigd/goql
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2018-03-12 13:26:36
Pushed At2018-10-13 14:12:11
Last Commit At2018-10-13 16:12:07
Release Count0
用户参与
Stargazers Count302
Watchers Count10
Fork Count13
Commits Count79
Has Issues Enabled
Issues Count12
Issue Open Count7
Pull Requests Count7
Pull Requests Open Count0
Pull Requests Close Count2
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private