nameExists reports whether a row with name exists, optionally excluding an id.
(ctx context.Context, q queryer, name string, excludeID int64)
| 219 | |
| 220 | // nameExists reports whether a row with name exists, optionally excluding an id. |
| 221 | func nameExists(ctx context.Context, q queryer, name string, excludeID int64) (bool, error) { |
| 222 | var existingID int64 |
| 223 | err := q.QueryRowContext(ctx, `SELECT id FROM instructions WHERE name = ?`, name).Scan(&existingID) |
| 224 | if err == sql.ErrNoRows { |
| 225 | return false, nil |
| 226 | } |
| 227 | if err != nil { |
| 228 | return false, err |
| 229 | } |
| 230 | return existingID != excludeID, nil |
| 231 | } |
| 232 | |
| 233 | // writeManagedFile atomically writes content to the managed file for name. |
| 234 | func writeManagedFile(name, content string) error { |
no test coverage detected