server-db.sql 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. -- ----------------------------------------------------------------------------------------
  2. -- Simple table used only for toggling the relevant device
  3. --
  4. -- It should also be noted that is is primarily designed for use with
  5. -- sqlite3, so use that.
  6. --
  7. -- Written by:
  8. -- Christian Kissinger
  9. -- ----------------------------------------------------------------------------------------
  10. -- ----------------------------------------------------------------------------------------
  11. -- Everything below here is related to the server.
  12. --
  13. -- And this primarily exists for the discovery feature
  14. --
  15. ------------------------------------------------------------------------------------------
  16. -- A very simple table, should only hold 1 entry, ideally anyway.
  17. CREATE TABLE srvr (
  18. uuid_str VARCHAR NOT NULL,
  19. PRIMARY KEY( uuid_str )
  20. );
  21. -- Example (and one time) insertion
  22. -- INSERT INTO srvr VALUES( "abcd1234-5432-7890-a34f-6924a3b2f3dd")
  23. -- Return UUID for server if requested
  24. -- SELECT uuid_str FROM srvr
  25. -- ----------------------------------------------------------------------------------------
  26. -- Everything below here is related to the device table
  27. -- ----------------------------------------------------------------------------------------
  28. CREATE TABLE device (
  29. dev_name VARCHAR NOT NULL,
  30. dev_on INT NOT NULL,
  31. dev_off INT NOT NULL,
  32. dev_pulse INT NOT NULL,
  33. dev_toggled INT NOT NULL,
  34. PRIMARY KEY( dev_name )
  35. );
  36. -- example insertion
  37. -- INSERT INTO device VALUES( 'outlet0', 5592371, 5592380, 189, 0 );
  38. -- ----------------------------------------------------------------------------------------
  39. -- Most useful example queries here
  40. -- ----------------------------------------------------------------------------------------
  41. -- Return list of devices for client
  42. -- SELECT dev_name FROM device;
  43. -- Return dev_on and dev_pulse from device 'outlet0'
  44. -- SELECT dev_on, dev_pulse FROM device WHERE dev_name='outlet0'
  45. -- Return dev_off and dev_pulse from device 'outlet0'
  46. -- SELECT dev_off, dev_pulse FROM device WHERE dev_name='outlet0'
  47. -- Return dev_name from device 'outlet0'
  48. -- SELECT dev_name FROM device WHERE dev_on=5592371 OR dev_off=5592380;
  49. -- ----------------------------------------------------------------------------------------
  50. -- Update values (mostly name) examples
  51. -- ----------------------------------------------------------------------------------------
  52. -- change name 'outlet0' to 'light0'
  53. -- UPDATE device SET dev_name='light0' WHERE dev_name='outlet0';
  54. -- change toggled from 0 to 1 (false to true) on device 'light0'
  55. -- UPDATE device SET dev_toggled=1 WHERE dev_name='light0'
  56. -- If we had to update the dev_on code, this would be how.
  57. -- It would be a similar process for the dev_off code and dev_pulse.
  58. -- change dev_on from 5592371 to 5592372 on device 'light0'
  59. -- UPDATE device SET dev_on=5592372 WHERE dev_name='light0';
  60. -- ----------------------------------------------------------------------------------------
  61. -- Delete Entries example(s)
  62. -- ----------------------------------------------------------------------------------------
  63. -- delete light0 entry
  64. -- DELETE FROM device WHERE dev_name='light0';