GithubHelp home page GithubHelp logo

Comments (5)

kenshaw avatar kenshaw commented on May 25, 2024

So: the usql code is very modular, as its constiuent packages don't have many interdependencies (thank you Go!). You could easily conjure up a different frontend that uses the Handler to do exactly what you've described. Please see the main.go and args.go, it's really a trivial amount of code involved.

With regards to completions and a \complete command, please note that completions in usql aren't complete (no pun intended). They currently only work on a few databases, and only complete some entity names. As such, I can't really see how the benefit of a \complete command. You can dig into the code and use the actual completer engine, as it's also modular and completely separable from the usql code.

from usql.

astoff avatar astoff commented on May 25, 2024

@kenshaw: Thanks for the explanation. What you describe should work indeed.

Still regarding the use of usql as a library, perhaps you can help me with a question about the build tags (I'm new to Go).

The installation instructions involving go install -tags somedriver github.com/xo/usql work as expected. However, if I create a simple program that imports usql like the one below, the resulting binary is quite small and prints 0; that is, no drivers are linked.

package main

import (
	"fmt"
	"github.com/xo/usql/drivers"
)

func main() {
	available := drivers.Available()
	fmt.Printf("%v\n", len(available))
}

How am I supposed to pass build tags to usql when it is used as a dependency?

from usql.

kenshaw avatar kenshaw commented on May 25, 2024

You don't need the build tags when building it as a library. That's a hack I whipped up to change the configuration at build time, but without needing to modify the source code.

You can manually import any of the drivers you want, via the following:

package main

import (
	"fmt"
	"sort"

	"github.com/xo/usql/drivers"
	_ "github.com/xo/usql/drivers/mysql"
	"golang.org/x/exp/maps"
)

func main() {
	available := drivers.Available()
	keys := maps.Keys(available)
	sort.Strings(keys)
	for _, key := range keys {
		fmt.Println(key)
	}
}

You can import any (or none) of the drivers you'd like to import. Good luck!

from usql.

astoff avatar astoff commented on May 25, 2024

Thanks for the hints! My usql integration for Emacs is working; for the record, it can be found here.

As a friendly piece of feedback, I wanted to say again that you like the idea of supporting other types of UIs, it would be nice to provide a dedicated "eval" function. In my case, it was enough to hack into the usql read-eval-print loop and manipulate the strings it receives, but a different situation might have required to copy and adapt the whole of Handler.Run, which is a rather long function. Conceptually, it does both the "E" and "L" of REPL at once.

from usql.

kenshaw avatar kenshaw commented on May 25, 2024

Handler.Run is the entire REPL. A third-party package (github.com/gohxs/readline) is used to actually do the line reading, and other packages within usql handle the bulk of the operations, but it's that Run func that the main hands off to after setting up the environment that does the majority of the the "work".

from usql.

Related Issues (20)

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.