REMINDER
is there a way to connect to the database when developing locally?
-
Hey there folks I was wondering if there is a way to connect to the DB when developing locally?
-
@Linda-MacDonald said in is there a way to connect to the database when developing locally?:
Hey there folks I was wondering if there is a way to connect to the DB when developing locally?
Hi Linda, you don't have direct access to the DB as it's cloud hosted. The only way you can access it is through API so locally or not doesn't change the way you would do it.
-
@Wassim yeah I understand I didn't clarify - I need the db name in order to create the api, do I just use the name that I give the db? - or is it perhaps easier to upload the project first and then hook it up to the db?
-
Linda, are you using the cloudbackend npm module? If you do, you shouldn't need to know the DB name.
I run SQL queries against the CloudBackend DB all the time while developing locally
var cloudbackend = require('appdrag-cloudbackend'); cloudbackend.init(process.env.APIKEY, process.env.APPID); await cloudbackend.sqlSelect(`SELECT column FROM Table `).then(response => { // Do stuff here });
I think you need requests too, as a dependency.
Are you using Node.js? If not, that is indeed where it gets tricker, but if I remember right it's doable. Let us know!
-
@Daniel-Mulroy THANK YOU SOOOOOOOOOOOOOOOOOOO MUCH!!!!!! I plumb forgot about the possibity to generate an apikey etc on the backend here
-
I have a script I use to 'fake' a lambda invocation, complete with POST variables, env. vars, etc.
If that's helpful to you let me know.
You invoke the 'testing' script and pass the actual code you want to use as an argument on the command line. That way you can test functions that have parameters, etc.
-
@Daniel-Mulroy YES PLEASE π€©π€©π€©π€©if you dont mind sharing that would be sweet
-
Code at the end, copy and paste into a text file and save as "testFunction.js"
These instructions are for Mac, would love to know better how to do it on PC
In the Terminal, navigate to the folder containing testFunction.js, then type:
file="pathToSomeOtherFunctionFileIWantToTest.js" node testFunction.js
testFunction will read the filename from the "file" parameter, and execute it, with full logging to stdout.
Hope this helps!
(Minor note, I had to clean this up a bit to remove some sensitive info from my own implementation, like API keys, etc. If I made a syntax typo, it should be minor, and please let me know so I can clean it up. Thanks!
const request = require("request-promise-native"); // Creates and assigns variables as process.env vars, so you can use them as you would the env vars from the AppDrag interface. Object.assign(process.env, envVars); const envVars = { APIKEY : "your-appdrag-api-key-here", APPID : "your-appdrag-project-id-here", someVar : "someValue" } //import your handler file or main file of Lambda let fn = require(`./${process.env.file}`); console.log("Starting up... " + process.env.file) process.on('beforeExit', (code) => { console.log('Process beforeExit event with code: ', code); }); process.on('exit', (code) => { console.log('Process exit event with code: ', code); }); //Call your exports function with required params //In AWS lambda these are event, content, and callback //event and content are JSON object and callback is a function fn.handler({ // Incoming parameters from the request. "GET": { "someGETvar" : "someGETvalue" }, "POST": { "somePOSTvar": "somePOSTvalue" }, "HEADERS": { ip: "0.0.0.0", "User-Agent": "LOCAL TESTING"} }, //event vars {'eventVar':"someEVENTvar"}, //content function(data, ss) { //callback function with two arguments console.log(data); console.log(ss); });
-
@Daniel-Mulroy thank you so much for thisπ€©...hope it didnt disturb your work flow you're in luck, am on windows so once I get up and running I'll let you know