mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Make storage providers generate row limit clause
This commit is contained in:
parent
8515a77403
commit
2ddd7ada9b
5 changed files with 36 additions and 0 deletions
3
core/env/provider.go
vendored
3
core/env/provider.go
vendored
|
@ -111,4 +111,7 @@ type StoreProvider interface {
|
|||
// IsFalse returns storage provider boolean FALSE:
|
||||
// MySQL is 0, PostgresSQL is FALSE, SQL Server is 0
|
||||
IsFalse() string
|
||||
|
||||
// RowLimit returns SQL for limited number of returned rows
|
||||
RowLimit(max int) string
|
||||
}
|
||||
|
|
|
@ -119,3 +119,21 @@ func (c *Context) IsTrue() string {
|
|||
func (c *Context) IsFalse() string {
|
||||
return c.Runtime.StoreProvider.IsFalse()
|
||||
}
|
||||
|
||||
// RowLimitVariants returns the SQL clause for limiting rows.
|
||||
// Depending on the storage provider, the limit clause goes either
|
||||
// at the start of the query or the end.
|
||||
func (c *Context) RowLimitVariants(max int) (variantStart string, variantEnd string) {
|
||||
variantStart = ""
|
||||
variantEnd = ""
|
||||
|
||||
if c.Runtime.StoreProvider.Type() == env.StoreTypeSQLServer {
|
||||
// SQL Server and variants use 'SELECT TOP nnn' syntax.
|
||||
variantStart = c.Runtime.StoreProvider.RowLimit(max)
|
||||
} else {
|
||||
// MySQL and variants use 'SELECT ... LIMIT nnn' syntax.
|
||||
variantEnd = c.Runtime.StoreProvider.RowLimit(max)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -364,6 +364,11 @@ func (p MySQLProvider) IsFalse() string {
|
|||
return "0"
|
||||
}
|
||||
|
||||
// RowLimit returns SQL for limiting number of rows returned.
|
||||
func (p MySQLProvider) RowLimit(max int) string {
|
||||
return fmt.Sprintf("LIMIT %d", max)
|
||||
}
|
||||
|
||||
// convertDatabaseVersion turns database version string as major,minor,patch numerics.
|
||||
func convertDatabaseVersion(v string) (ints []int, err error) {
|
||||
ints = []int{0, 0, 0}
|
||||
|
|
|
@ -305,3 +305,8 @@ func (p PostgreSQLProvider) IsTrue() string {
|
|||
func (p PostgreSQLProvider) IsFalse() string {
|
||||
return "false"
|
||||
}
|
||||
|
||||
// RowLimit returns SQL for limiting number of rows returned.
|
||||
func (p PostgreSQLProvider) RowLimit(max int) string {
|
||||
return fmt.Sprintf("LIMIT %d", max)
|
||||
}
|
||||
|
|
|
@ -370,3 +370,8 @@ func (p SQLServerProvider) IsTrue() string {
|
|||
func (p SQLServerProvider) IsFalse() string {
|
||||
return "0"
|
||||
}
|
||||
|
||||
// RowLimit returns SQL for limiting number of rows returned.
|
||||
func (p SQLServerProvider) RowLimit(max int) string {
|
||||
return fmt.Sprintf("TOP %d", max)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue