Add support for user functions (#608)
* Add initial support for functions * Show functions definitions * Fix client tests * Fix schema objects search * Perform partial matching for functions * Add function test * Make sure to close client connections so that database could be dropped in tests * Fix lint * Allow to copy the view/functions definitions * Nits
This commit is contained in:
@@ -342,13 +342,21 @@ func GetSchemas(c *gin.Context) {
|
||||
|
||||
// GetTable renders table information
|
||||
func GetTable(c *gin.Context) {
|
||||
var res *client.Result
|
||||
var err error
|
||||
var (
|
||||
res *client.Result
|
||||
err error
|
||||
)
|
||||
|
||||
if c.Request.FormValue("type") == client.ObjTypeMaterializedView {
|
||||
res, err = DB(c).MaterializedView(c.Params.ByName("table"))
|
||||
} else {
|
||||
res, err = DB(c).Table(c.Params.ByName("table"))
|
||||
db := DB(c)
|
||||
tableName := c.Params.ByName("table")
|
||||
|
||||
switch c.Request.FormValue("type") {
|
||||
case client.ObjTypeMaterializedView:
|
||||
res, err = db.MaterializedView(tableName)
|
||||
case client.ObjTypeFunction:
|
||||
res, err = db.Function(tableName)
|
||||
default:
|
||||
res, err = db.Table(tableName)
|
||||
}
|
||||
|
||||
serveResult(c, res, err)
|
||||
@@ -541,3 +549,9 @@ func DataExport(c *gin.Context) {
|
||||
badRequest(c, err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetFunction renders function information
|
||||
func GetFunction(c *gin.Context) {
|
||||
res, err := DB(c).Function(c.Param("id"))
|
||||
serveResult(c, res, err)
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ func SetupRoutes(router *gin.Engine) {
|
||||
api.GET("/tables/:table/info", GetTableInfo)
|
||||
api.GET("/tables/:table/indexes", GetTableIndexes)
|
||||
api.GET("/tables/:table/constraints", GetTableConstraints)
|
||||
api.GET("/functions/:id", GetFunction)
|
||||
api.GET("/query", RunQuery)
|
||||
api.POST("/query", RunQuery)
|
||||
api.GET("/explain", ExplainQuery)
|
||||
|
||||
Reference in New Issue
Block a user