schema.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package common
  2. // Database query constants for the SQLite locks database
  3. const (
  4. // SelectInstanceLocksSQL selects all instance locks ordered by creation time
  5. SelectInstanceLocksSQL = `
  6. SELECT id, held_by, lock_type, lock_target, locked_at
  7. FROM locks
  8. WHERE lock_type = 'instance'
  9. ORDER BY locked_at ASC
  10. `
  11. SelectInstanceLockByHolderSQL = `
  12. SELECT held_by, lock_target, locked_at
  13. FROM locks
  14. WHERE held_by = ? AND lock_type = 'instance'
  15. `
  16. SelectInstanceLockHoldersAscSQL = `
  17. SELECT held_by, lock_target, locked_at
  18. FROM locks
  19. WHERE lock_type = 'instance'
  20. ORDER BY locked_at ASC
  21. `
  22. // DeleteInstanceLockSQL deletes an instance lock by address
  23. DeleteInstanceLockSQL = `
  24. DELETE FROM locks
  25. WHERE held_by = ? AND lock_type = 'instance'
  26. `
  27. InsertFileLockSQL = `
  28. INSERT INTO locks (held_by, lock_type, lock_target, locked_at)
  29. VALUES (?, 'file', ?, ?)
  30. `
  31. // DeleteFileLockSQL deletes a file lock by holder and target
  32. DeleteFileLockSQL = `
  33. DELETE FROM locks
  34. WHERE held_by = ? AND lock_type = 'file' AND lock_target = ?
  35. `
  36. // CountInstanceLockSQL counts instance locks for a given address
  37. CountInstanceLockSQL = `
  38. SELECT COUNT(*) FROM locks
  39. WHERE held_by = ? AND lock_type = 'instance'
  40. `
  41. // InsertInstanceLockSQL inserts or replaces an instance lock
  42. InsertInstanceLockSQL = `
  43. INSERT OR REPLACE INTO locks (held_by, lock_type, lock_target, locked_at)
  44. VALUES (?, 'instance', ?, ?)
  45. `
  46. )