0

Mirror tables in different databases

Hi, Is there a system to have a copy of one database table in another database and have it so that when I add or change something in one table it automatically updates the other table? Thanks

4 replies

null
    • Rafael Sanchis
    • Rafael_Sanchis
    • 1 yr ago
    • Reported - view

    On Gear / Edit fields... you can duplicate a table 

    • Fred
    • 1 yr ago
    • Reported - view

    There are two ways to update tables in different DBs.

    1) If you have a private cloud instance then Ninox has built in tools to talk between DBs. I am so hoping this comes out in Public cloud.

    2) Use an integration tool, Make or Zapier or others, to talk between DBs.

    • giuseppe
    • 1 yr ago
    • Reported - view

    Ok thanks, from what I understand there is no internal way to communicate between databases

      • Daniel_Berrow
      • 1 yr ago
      • Reported - view

       You can do this via the API tools provided in the documentation

      You can set up trigger on creation of record to create a record in the mirrored table, and have trigger on update within your fields to send over the information to the other record in the mirrored table

      let data := {
                  fields: {
                      'field': 'record data',
                  }
              };
          let response := http("POST", "https://{NinoxURL}/v1/teams/{teamID}/databases/{databaseID}/tables/{tableID}/records/", {
                  Authorization: "Bearer " + {APIkey},
                  'Content-Type': "application/json"
              }, data);
          alert(response.result);
      

      Here is a stripped back example of mine, anything in curly brackets must be set as what your databases value should be, for example your databaseID can be found in your url or by using the formula 'databaseId()'

      you can have as many fields as you want being sent across, they are sent as a JSON object, ie

      fields: {
           data1: data,
           data2: data2,
           data3: data3
      }
      

      In my experience, when I do this I send over the new record ID, so then they effectively have a link, and I created a function to utilise the API in querying another database to find that record, for when doing updates on individual fields 

      function putDatabase(teamID : text,databaseId : text,tableID : text,recordId : text,query : any,key : text) do
          let url := "https://{your url}/v1/teams/" + teamID + "/databases/" + databaseId +
              "/tables/" +
              tableID +
              "/records/" +
              recordId;
          let headers := {
                  Authorization: "Bearer " + {your api key},
                  'Content-Type': "application/json"
              };
          let data := {
                  fields: query
              };
          let response := http("PUT", url, headers, data);
          void
      end;
      

      I use this function with this format

      putDatabase("TeamID", "DatabaseID", "TableID", "recordID", {
                  'Item Name': t.'Item Name'
              }, key)
      

      I'm happy to provide any more information to try and help you with this further

Content aside

  • 1 yr agoLast active
  • 4Replies
  • 72Views
  • 4 Following