Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sqlite view #2

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
func init() { //nolint:gochecknoinits
level := os.Getenv("REST_LOG_LEVEL")
switch strings.ToLower(level) {
case "trace":
logLevel = TraceLevel
case "error":
logLevel = ErrorLevel
case "warn":
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ func (s *Server) get(r *http.Request, tableName string, urlQuery *sql.URLQuery,
Msg: fmt.Sprintf("expect singular data, but got %d rows", len(objects)),
}
}
return objects[0] // return single map[string]any
return objects[0]
}
return objects // return []map[string]any
return objects
}

func (s *Server) count(r *http.Request, tableName string, urlQuery *sql.URLQuery) any {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/helper_my.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func (h MyHelper) GetTablesSQL() string {
return `
SELECT TABLE_NAME as name
FROM information_schema.TABLES
WHERE TABLE_TYPE LIKE 'BASE_TABLE' AND TABLE_SCHEMA=DATABASE();
WHERE (TABLE_TYPE = 'BASE_TABLE' OR TABLE_TYPE = 'view') AND TABLE_SCHEMA=DATABASE();
`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/helper_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (h SQLiteHelper) GetTablesSQL() string {
FROM
sqlite_schema
WHERE
type ='table' AND
(type ='table' OR type = 'view') AND
name NOT LIKE 'sqlite_%';
`
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/urlquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
// date functions
"date", "date_format", "date_part", "date_trunc", "extract", "hour",
"minute", "month", "second", "utctimestamp", "weekofday", "year",
"time", "datetime", "julianday", "unixepoch", "strftime",
// string functions
"bit_length", "chr", "char_length", "left", "length", "ord", "trim",
}
Expand Down