| 83 | } |
| 84 | |
| 85 | func renderSQLitePathString(pathString string, shardID int, field string) (string, error) { |
| 86 | // This function substitutes {{ShardId}} and {{Field}} in PathString. |
| 87 | var templ *template.Template |
| 88 | var doc bytes.Buffer |
| 89 | replacementVars := map[string]string{ |
| 90 | "ShardId": fmt.Sprintf("%04d", shardID), |
| 91 | "Field": field, |
| 92 | } |
| 93 | |
| 94 | templ, err := template.New("sqlite").Parse(pathString) |
| 95 | if err != nil { |
| 96 | return "", err |
| 97 | } |
| 98 | |
| 99 | err = templ.Execute(&doc, replacementVars) |
| 100 | if err != nil { |
| 101 | return "", err |
| 102 | } |
| 103 | dir := doc.String() |
| 104 | if dir == "" { |
| 105 | return "", fmt.Errorf("empty rendered path template") |
| 106 | } |
| 107 | return dir, nil |
| 108 | } |
| 109 | |
| 110 | // runSQLCommands is an helper function that will run some commands on an SQL transaction. |
| 111 | func runSQLCommands(tx *sql.Tx, commands []string) error { |