mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQLStore: Create utility for bulk inserts (#57632)
* Add batchsize to dialects * Some intermediary progress * Reflection-based implementation * Validate batch size * Implement a few simple tests * Fix linter error * Add debug message when falling back to default batch size
This commit is contained in:
@@ -26,6 +26,7 @@ type Dialect interface {
|
||||
Default(col *Column) string
|
||||
BooleanStr(bool) string
|
||||
DateTimeFunc(string) string
|
||||
BatchSize() int
|
||||
|
||||
OrderBy(order string) string
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ func (db *MySQLDialect) BooleanStr(value bool) string {
|
||||
return "0"
|
||||
}
|
||||
|
||||
func (db *MySQLDialect) BatchSize() int {
|
||||
return 1000
|
||||
}
|
||||
|
||||
func (db *MySQLDialect) SQLType(c *Column) string {
|
||||
var res string
|
||||
switch c.Type {
|
||||
|
||||
@@ -45,6 +45,10 @@ func (db *PostgresDialect) BooleanStr(value bool) string {
|
||||
return strconv.FormatBool(value)
|
||||
}
|
||||
|
||||
func (db *PostgresDialect) BatchSize() int {
|
||||
return 1000
|
||||
}
|
||||
|
||||
func (db *PostgresDialect) Default(col *Column) string {
|
||||
if col.Type == DB_Bool {
|
||||
if col.Default == "0" {
|
||||
|
||||
@@ -40,6 +40,12 @@ func (db *SQLite3) BooleanStr(value bool) string {
|
||||
return "0"
|
||||
}
|
||||
|
||||
func (db *SQLite3) BatchSize() int {
|
||||
// SQLite has a maximum parameter count per statement of 100.
|
||||
// So, we use a small batch size to support write operations.
|
||||
return 10
|
||||
}
|
||||
|
||||
func (db *SQLite3) DateTimeFunc(value string) string {
|
||||
return "datetime(" + value + ")"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user