Pi-DB.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //Pi-DB Access Library
  2. class PiDB{
  3. //dbn -> Store the name of the database
  4. //DBpath -> Store the path of the db
  5. constructor(PiDBpath, dbname) {
  6. if (PiDBpath.slice(-1) != "/"){
  7. PiDBpath += "/";
  8. }
  9. this.dbn = dbname;
  10. this.DBpath = PiDBpath;
  11. }
  12. request(query){
  13. //Request Data from the PiDB System with the given query
  14. //console.log(this.DBpath + "table_r.php");
  15. //console.log(this.dbn);
  16. return $.ajax({
  17. url: this.DBpath + "/table_r.php",
  18. type: "get",
  19. data: {db:this.dbn,opr:query}
  20. });
  21. }
  22. write(query){
  23. //Writing data to the PiDB
  24. return $.ajax({
  25. url: this.DBpath + "/table_w.php",
  26. type: "get",
  27. data: {db:this.dbn,opr:query}
  28. });
  29. }
  30. newDB(){
  31. //Creating a new database
  32. var oprs = 'newDB';
  33. return $.ajax({
  34. url: this.DBpath + "/DB_operation.php",
  35. type: "get",
  36. data: {db:this.dbn,opr:oprs}
  37. });
  38. }
  39. newTable(names,headers){
  40. //Creating a new table inside the current DB
  41. var oprs = 'createTable';
  42. return $.ajax({
  43. url: this.DBpath + "/table_w.php",
  44. type: "get",
  45. data: {db:this.dbn,opr:oprs,name:names,header:headers}
  46. });
  47. }
  48. }