Any contributions are welcome. If you found a bug, or a missing feature, take a look at existing issues and create a new one if needed.
You can also open up a pull request (PR) with code or documentation changes.
- Add a new schema in dburl.
- Create a new go package in
drivers
. It should have aninit()
function, that would calldrivers.Register()
. - Regenerate code in the
internal
package by runninginternal/gen.sh
. - Add any new required modules using
go get
or by editinggo.mod
manually and runninggo mod tidy
. - Run all tests, build
usql
and see if the new driver works. - Update
README.md
.
Tip: check out closed PRs for examples, and/or search the codebase for names of databases you're familiar with.
For \d*
commands to work, usql
needs to know how to read the structure of a database.
A driver must provide a metadata reader, by setting the NewMetadataReader
property
in the drivers.Driver
structure passed to drivers.Register()
. This needs to be a function
that given a database and reader options, returns a reader instance for this particular driver.
If the database has a information_schema
schema, with standard tables like tables
and columns
,
you can use an existing reader from the drivers/informationschema
package.
Since there are usually minor difference in objects defined in that schema in different databases,
there's a set of options to configure this reader. Refer to
the package docs for details.
If you can't use the informationschema
reader, consider implementing a new one.
It should implement at least one of the following reader interfaces:
- CatalogReader
- SchemaReader
- TableReader
- ColumnReader
- IndexReader
- IndexColumnReader
- FunctionReader
- FunctionColumnReader
- SequenceReader
Every of these interfaces consist of a single function, that takes a Filter
structure as an argument,
and returns a set of results and an error.
Example drivers using their own readers include:
sqlite3
oracle
andgodror
sharing the same reader
If you want to use the informationschema
reader, but need to override one or more readers,
use the metadata.NewPluginReader(readers ...Reader)
function. It returns an object calling
reader functions from the last reader passed in the arguments, that implements it.
Example drivers extending an informationschema
reader using a plugin reader:
postgres
\d*
commands are actually implemented by a metadata writer. There's currently only one,
but it too can be replaced and/or extended.
If a driver provides a metadata reader, the default completer will use it.
A driver can provide it's own completer, by setting the NewCompleter
property
in the drivers.Driver
structure passed to drivers.Register()
.