{"_id":"@drama_llama/rift","_rev":"1-55ad296414a77f738f1eb9c2ca77092d","name":"@drama_llama/rift","dist-tags":{"latest":"2.1.0"},"versions":{"2.1.0":{"name":"@drama_llama/rift","version":"2.1.0","description":"Server and Mysql database connector.","main":"Rift.js","directories":{"lib":"lib"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/jbradleybriggs/Rift.git"},"author":{"name":"J. Bradley Briggs"},"license":"ISC","bugs":{"url":"https://github.com/jbradleybriggs/Rift/issues"},"homepage":"https://github.com/jbradleybriggs/Rift#readme","dependencies":{"chalk":"^2.4.2","mysql":"^2.17.1"},"gitHead":"9218b15956e01b35233ed58fe531d60b125199c4","_id":"@drama_llama/rift@2.1.0","_npmVersion":"6.5.0-next.0","_nodeVersion":"11.6.0","_npmUser":{"name":"drama_llama","email":"jason.briggs@techss.co.za"},"dist":{"integrity":"sha512-oOQK6D5wKqPoCSNEjvgRPiakmsO1rbcF51jKZgVcLdMLBOkEeigVDzHiDU8c4bzt2OGJkMs/3GqYqIcCNovbXw==","shasum":"e0f0bb84e6782a00d79dbf8981e7488fa17b25f2","tarball":"https://registry.npmjs.org/@drama_llama/rift/-/rift-2.1.0.tgz","fileCount":5,"unpackedSize":24264,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdJIBsCRA9TVsSAnZWagAA+WgQAIuLJmZ8hDv4y/COU6Am\nPbjjRz1VGWIuCtO9a33ABV2sj3dg/UbvCW0rbXwrO4Go7jgMJ24kP1O6LauW\nY/c0OVANemfPCRoetP9KgIzp2Liga7EteaeXmIgLosAcjx/YWahcke6OMGBI\n5Ym9bPQExFAsY8VvUDOLUGsbsWDIgcQMqyTD9cMVYzFY3Jy7aKAaY5p487Nw\n8PDKPGT1jMF2PwuFLqjZxbHMUA+UM6/+Wsz4u+0jIItEU/X8tGrTJKdlAgq7\nS0/BvDNb0dqDB/okQrhXaltgOsXLPzyThV/rRvz/i5y3VlvUhPwbb6c8pB0L\n7HY1Tjgc4NK8vf4nvg6cTm9bWXG+4ODpfKyFP8/Ws4OxIcfVQ4hbr2cDeGWs\nJ3wSnG0xq5TE7V/pVWvRHfCaId20TBffw5bME50Qt50UjcHdtlfnRFuTHa+c\niFiB5DZxWNlXTDK+YwRzwAmJhFuHaXNXXmGhN5E/2Rb8jH2BfebbiA2wGyq8\nlmpfFkx1zbyjCQpdDYf/XRV3URA6WvaiB1AAkYK/RBvp6ghgoJQEAVG2zXpJ\nTvLOVKDBp/CZL9A/cfcly94DN0C7hSDoZWGko4c9og/9v9XauPueQyA+V2D/\nHzqvgxgNAQenrcB6bt0kVPj0wnbq/RoEdU9jJZBDF6sTuVk+9g3mno0tIXCB\nzqjr\r\n=2RD4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBT/efaz1WWgCbfI0wcnlp9yWFJYNXwBP1tdM1rZh5eyAiAu0Y/cgGqI5fqBsh6OTCi4vxJXScmSLduyrLewk0iJPg=="}]},"maintainers":[{"name":"drama_llama","email":"jason.briggs@techss.co.za"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rift_2.1.0_1562673259512_0.15923655228931044"},"_hasShrinkwrap":false}},"time":{"created":"2019-07-09T11:54:19.285Z","2.1.0":"2019-07-09T11:54:19.661Z","modified":"2022-04-05T05:36:34.160Z"},"maintainers":[{"name":"drama_llama","email":"jason.briggs@techss.co.za"}],"description":"Server and Mysql database connector.","homepage":"https://github.com/jbradleybriggs/Rift#readme","repository":{"type":"git","url":"git+https://github.com/jbradleybriggs/Rift.git"},"author":{"name":"J. Bradley Briggs"},"bugs":{"url":"https://github.com/jbradleybriggs/Rift/issues"},"license":"ISC","readme":"# Rift\n\n## Running the Server\n```bash\n  node ./lib/RiftServer.js\n```\nby default this runs on port 8082, to make the server run on another port, specify\nthe port number in the terminal as an argument:\n```bash\n  node ./lib/RiftServer.js 9000\n```\nthis will run the server on port 9000.\n\n## Getting data from the database\nThe first thing we need to do is build a database request; this will allow the server to connect\nto whichever host, database and table you need.\n```js\n  var dbRequest = {\n    host: \"localhost\", //optional, default 'localhost'\n    username: \"your_db_username\", //required\n    password: \"your_db_password\", //required\n    db: \"the_db_you_are_connecting_to\", //required\n    table: \"the_table_in_the_db\", //required\n    op: \"GET\" //or \"SET\", \"DELETE\", \"SEARCH\", //optional, default \"GET\"\n    fields: ['name', 'surname', 'a_field', 'some_other_field'], //the fields you want to get (if this is [], it will get all the fields)\n    conditions: {}, //optional\n    options: {group_by: 'a_field', order_by: {'name': 'asc', 'a_field': 'desc'}, limit: 100} //optional \n  }\n```\n\n## Connecting to the Server from the Client\nTo connect to the server and get the data we want, we need to create a new Request Object and pass in the dbRequest:\n```js\n  const url = \"http://localhost:8082\"; //url to where the server is running, not where the database is stored.\n  var request = new Request(url, {\n    method: \"POST\",\n    headers: {\n        \"Content-Type\": \"application/json\"\n        },\n    mode: \"cors\", // specify this to enable data to be sent across different ports\n    body: JSON.stringify(dbRequest) //send this as a string rather than an object\n  }) ;\n  \n```\nNow we simply do a fetch() - Note the fetch method returns a Promise that resolves to the Response. By chaining another Promise we can resolve to the Response parsed as JSON:\n```js\n  fetch(request) //send request to the server, which connects to the db and runs a query and sends back a response\n  .then((response) => response.json()) //once we have the response, parse it as json\n  .then((result) => { // result is now the result of the database query\n    //do something with 'result'\n  }) ;\n```\n\n","readmeFilename":"README.md"}