Use the table name from xCreate args in vtable example
This commit is contained in:
@@ -20,13 +20,19 @@ type githubModule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *githubModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
|
func (m *githubModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
|
||||||
|
// args holds the raw xCreate arguments: args[0] is the module name,
|
||||||
|
// args[1] the database name, args[2] the virtual table name, and any
|
||||||
|
// user arguments follow.
|
||||||
|
if len(args) < 3 {
|
||||||
|
return nil, fmt.Errorf("githubModule: unexpected arguments: %v", args)
|
||||||
|
}
|
||||||
err := c.DeclareVTab(fmt.Sprintf(`
|
err := c.DeclareVTab(fmt.Sprintf(`
|
||||||
CREATE TABLE %s (
|
CREATE TABLE %s (
|
||||||
id INT,
|
id INT,
|
||||||
full_name TEXT,
|
full_name TEXT,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
html_url TEXT
|
html_url TEXT
|
||||||
)`, args[0]))
|
)`, args[2]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -49,6 +55,9 @@ func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("fetching repositories: %s", resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user