Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    is there a way to connect to the database when developing locally?

    Cloud Backend (Cloud DB, API Builder)
    3
    9
    341
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Linda MacDonald
      Linda MacDonald last edited by

      Hey there folks πŸ™‚ I was wondering if there is a way to connect to the DB when developing locally?

      1 Reply Last reply Reply Quote 0
      • Wassim
        Wassim last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • Linda MacDonald
          Linda MacDonald last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • Daniel Mulroy
            Daniel Mulroy last edited by Daniel Mulroy

            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!

            Linda MacDonald 1 Reply Last reply Reply Quote 1
            • Linda MacDonald
              Linda MacDonald @Daniel Mulroy last edited by

              @Daniel-Mulroy THANK YOU SOOOOOOOOOOOOOOOOOOO MUCH!!!!!! πŸ™‚ I plumb forgot about the possibity to generate an apikey etc on the backend here

              1 Reply Last reply Reply Quote 0
              • Daniel Mulroy
                Daniel Mulroy last edited by

                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.

                Linda MacDonald 1 Reply Last reply Reply Quote 0
                • Linda MacDonald
                  Linda MacDonald @Daniel Mulroy last edited by Linda MacDonald

                  @Daniel-Mulroy YES PLEASE 🀩🀩🀩🀩if you dont mind sharing that would be sweet

                  1 Reply Last reply Reply Quote 0
                  • Daniel Mulroy
                    Daniel Mulroy last edited by

                    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);
                      });
                    
                    
                    Linda MacDonald 1 Reply Last reply Reply Quote -1
                    • Linda MacDonald
                      Linda MacDonald @Daniel Mulroy last edited by Linda MacDonald

                      @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 πŸ™‚

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post