Git Product home page Git Product logo

goql's Introduction

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/3mard/goql"
	"github.com/3mard/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/3mard/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 :) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.