I have created two app maker apps for different purposes. However, there are some data which is common between two apps.
How can I access/connect data between those app maker apps?
You will need to setup a Custom Google Cloud SQL instance. Then you can point both apps at the instance in Settings > Database > Switch to a Custom Cloud SQL Database
EDIT:
The other option is setting up a calculated reference to a model in another app.
Grant access to App2 in App1's Google Cloud SQL Instance Authorization Settings (see above link).
Create a Calculated model in App2.
In the Datasource query:
var conn = Jdbc.getCloudSqlConnection('jdbc:google:mysql://INSTANCE_CONNECTION_NAME/DATABASE_NAME', 'USERNAME', 'PASSWORD');
var stmt = conn.prepareStatement("SELECT * from TABLE_NAME");
var res = stmt.executeQuery();
var records = [];
while(res.next()) {
var record = app.models.MODEL_NAME.newRecord();
record.FIELD_1 = res.getString(1);
record.FIELD_2 = res.getString(2);
record.FIELD_3 = res.getString(3);
records.push(record);
}
res.close();
stmt.close();
conn.close();
return records;
Related
I have a project that uses CloudTableClient and query the cosmos db in this way:
var table = cloudTableClient.GetTableReference(tableName);
var cosmosResult = await table.ExecuteQuerySegmentedAsync(GetTableQuery<DynamicTableEntity>(queryOptions), tableContinuationToken, GetTableRequestOptions(requestOptions), operationContext);
If I use CosmosClient, I can set the ConnetionMode
CosmosClient client = new CosmosClient(connectionString,
new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway // ConnectionMode.Direct is the default
});
However, with CouldTableClient, seems I can't find an option to set this. Is it possible to use Direct Mode with CouldTableClient or I actually need to move everything to CosmosClient in order to do it.
I'm working on a offline-first flutter application that updates its records online to a MySQL database for a desktop web access and multi user access. My flutter application creates a new To-Do item for a To-Do List module and saves it locally to SQLITE. It then sends this new record to my online server via HTTP POST where it inserts this new record to the MYSQL database online and returns its recently created ID for the record. Then Flutter updates the record it created locally on SQLITE to save the "online_todo_id".
My problem: How do I write the syntax in flutter to set a new variable to the local SQLITE last_insert_rowid()?
var result = await db.insert(todoTABLE, todo.toDatabaseJson()); //Insert local record SQLITE
//......Http Post REST API to server, returns online_todo_id....
todo.online_todo_id=online_todo_id;// Here I set the new value in the todo object thats going to be updated.
var result2 = await db.rawQuery("SELECT last_insert_rowid() AS id");
var last_insert_rowid= last_insert_rowid(); //****--HELP HERE--****\\
var result2 = await db.update(todoTABLE, todo.toDatabaseJson(),
where: "todo_id = ?", whereArgs: [last_insert_rowid]);
Is it possible to connect the one App to more than one cloud SQL database?
I can connect to a single cloud SQL database within the App settings (projectName:regionName:instanceName/databaseName).
But I want to add models from more than one existing Cloud SQL database to my single App.
When Creating External Data Models, there is no option or settings to configure another/additional google cloud SQL database.
Any advise appreciated if there's a way to work around this?
Reference: Connect your app to an existing Google Cloud SQL database:
https://developers.google.com/appmaker/models/cloudsql#connect_your_app_to_an_existing_google_cloud_sql_database
John
Just tried this out:
App Maker server scripts have access to Google Service APIs. The JDBC class allows you to connect to Cloud SQL after adding 10 whitelisted IPs.
From: https://developers.google.com/apps-script/guides/jdbc add the following IPs to your access control in Cloud console:
64.18.0.0/20
64.233.160.0/19
66.102.0.0/20
66.249.80.0/20
72.14.192.0/18
74.125.0.0/16
173.194.0.0/16
207.126.144.0/20
209.85.128.0/17
216.239.32.0/19
I put this bit in a server script and attached it to a button and checked the output log and found that it worked.
function Connect() {
var address = 'instance_ip';
var user = 'username';
var pw = 'password';
var db = 'database_name';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
// read some rows
function readFrom() {
var conn = Jdbc.getConnection(dbUrl, user, pw);
var start = new Date();
var stmt = conn.createStatement();
stmt.setMaxRows(100);
var results = stmt.executeQuery('SELECT * FROM table_name');
var numCols = results.getMetaData().getColumnCount();
while (results.next()) {
var rowString = '';
for(var col = 0; col < numCols; col++) {
rowString += results.getString(col + 1) + '\t';
}
console.log(rowString);
}
results.close();
stmt.close();
}
readFrom();
}
Using this, you could have as many connections as you like. But this would not allow App Maker to recognize it as a datasource. You'd have to manually process the results until this feature is officially supported. (I like the idea and will make a repo library for this.)
In my design I want to use DocumentDB as a back-end for my multi tenant SAAS application.
As the data per tenant can be > 10gb I want to use a collection per tenant model.
The requirement is how can I ensure data isolation in my application. Tenant 1 should not be able to see tenant 2 data in code and on azure portal. How can I set permissions on collections for the same?
I want to use a collection per tenant model
You could try to create DocumentDB users for each tenant and associate the permissions with the user to control user access to collection/documents.
string documentCollectionlink = UriFactory.CreateDocumentCollectionUri("{database id}", "{collection id}").ToString();
string databaseLink = UriFactory.CreateDatabaseUri("{database id}").ToString();
Permission docPermission = new Permission
{
PermissionMode = PermissionMode.All,
ResourceLink = documentCollectionlink,
Id = "tenant1perm"
};
await client.CreateUserAsync(databaseLink, new User { Id = "tuser" });
docPermission = await client.CreatePermissionAsync(UriFactory.CreateUserUri("{database id}", "tuser"), docPermission);
and then you could read permissions for DocumentDB user and get access token based on the tenant, and create a new instance of the DocumentClient with the token to operate the resource.
var qclient = new DocumentClient(new Uri(EndpointUri), token);
We use the following code to communicate with DynamoDB:
using (var client = AWSClientFactory.CreateAmazonDynamoDBClient(RegionEndpoint.USEast1))
{
var table = Table.LoadTable(client, "Users");
var item = await table.GetItemAsync(id);
}
How can I force AWS.SDK for .NET to always use SSL connections? This is very important as we want to store user data including passwords in DynamoDB.
Here is a code snippet that will allow you to set the endpoint explicitly:
AmazonDynamoDBConfig config = new AmazonDynamoDBConfig();
config.ServiceURL = "https://dynamodb.us-east-1.amazonaws.com";
var client = new AmazonDynamoDBClient(config);
Feel free to replace the region (us-east-1) with any other AWS region.
This example is based on the documentation available here on setting the endpoint: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TestingDotNetApiSamples.html