can return fs.ErrExist
(ctx context.Context, file *WaveFile)
| 14 | |
| 15 | // can return fs.ErrExist |
| 16 | func dbInsertFile(ctx context.Context, file *WaveFile) error { |
| 17 | // will fail if file already exists |
| 18 | return WithTx(ctx, func(tx *TxWrap) error { |
| 19 | query := "SELECT zoneid FROM db_wave_file WHERE zoneid = ? AND name = ?" |
| 20 | if tx.Exists(query, file.ZoneId, file.Name) { |
| 21 | return fs.ErrExist |
| 22 | } |
| 23 | query = "INSERT INTO db_wave_file (zoneid, name, size, createdts, modts, opts, meta) VALUES (?, ?, ?, ?, ?, ?, ?)" |
| 24 | tx.Exec(query, file.ZoneId, file.Name, file.Size, file.CreatedTs, file.ModTs, dbutil.QuickJson(file.Opts), dbutil.QuickJson(file.Meta)) |
| 25 | return nil |
| 26 | }) |
| 27 | } |
| 28 | |
| 29 | func dbDeleteFile(ctx context.Context, zoneId string, name string) error { |
| 30 | return WithTx(ctx, func(tx *TxWrap) error { |