Documentation
¶
Overview ¶
Package bartlett automatically generates an API from your database schema.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bartlett ¶
type Bartlett struct {
DB *sql.DB
Driver Driver
Tables []Table
Users UserIDProvider
}
Bartlett holds all of the configuration necessary to generate an API from the database.
type Driver ¶
type Driver interface {
GetColumns(db *sql.DB, t Table) ([]string, error)
MarshalResults(rows *sql.Rows, w http.ResponseWriter) error
}
The Driver interface contains database-specific code, which I'm trying to keep to a minimum. Implement a column-identifying function and a result marshaling function for your database of choice.
type IDSpec ¶
type IDSpec struct {
Name string
Generator func() interface{}
}
An IDSpec is used for primary keys that are generated by the application rather than the database. If you need a random ID, for example, this is where you would generate it. This column is protected from tampering by API users in INSERT and UPDATE operations.
type ResultMarshaler ¶
type ResultMarshaler func(rows *sql.Rows, w http.ResponseWriter) error
A ResultMarshaler interprets a database result set, selects appropriate Go types, and writes JSON to the output stream. This is necessary because all of the databases have different types and their drivers respond to ScanType in different ways.
type Route ¶ added in v0.2.0
type Route struct {
Handler http.HandlerFunc
Path string
}
type Table ¶
type Table struct {
Name string
IDColumn IDSpec
Writable bool
UserID string
// contains filtered or unexported fields
}
A Table represents a table in the database. Name is required. Writable determines whether the table allows INSERT, UPDATE, and DELETE queries. Default is read-only. UserID is the name of column containing user IDs. It should match the output of the UserIDProvider passed to Bartlett. If UserID is left blank, all rows will be available regardless of the UserIDProvider.
type UserIDProvider ¶
A UserIDProvider is a function that is able to use an incoming request to produce a user ID.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mariadb provides a Bartlett driver for MariaDB databases.
|
Package mariadb provides a Bartlett driver for MariaDB databases. |
|
Package sqlite3 provides a Bartlett driver for SQLite3 databases.
|
Package sqlite3 provides a Bartlett driver for SQLite3 databases. |