appmaker data: connect to multiple Cloud SQL databases - google-app-maker

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

Related

Scraping wallets address on etherscan to .XLMS

I'm a student in IT Big Data, I'm currently working on a school project where I want to create a graph of all recent transaction. But can't find a good way to get the data correctly from the API anybody has an idea to do it ?
My personal recommendation is to not use Etherscan, and instead to use ethers.js and an RPC provider like infura or alchemy - or if you're feeling ambitious, run your own node. Instantiate a provider and listen for the block event: https://docs.ethers.io/v5/api/providers/provider/#Provider--events. If you want to listen for EIP-20 token transfers only, you can use the answer in this question: https://ethereum.stackexchange.com/questions/87643/how-to-listen-to-contract-events-using-ethers-js
Getting the data manually might seem more complicated, but it's actually more simple (and quicker/more customizable!) than polling the Etherscan API.
So thanks for your answer, I chose to work with infura and JS here is the ways i made it work, with that you ll get all the transaction from 150 blocks on mainnet :
async function data() {
var Web3 = require('web3');
var provider = 'https://mainnet.infura.io/v3/apikey';
var web3Provider = new Web3.providers.HttpProvider(provider);
var web3 = new Web3(web3Provider);
console.log("transaction per block");
var k= 15623650;
for(var j= 15623650;k-j<150;j--){
var a;
var onumber_of_transaction_by_block = await web3.eth.getBlockTransactionCount(j).then(a = this);
var Number_by_block =await Number(onumber_of_transaction_by_block);
for(var i=1;i<=Number_by_block-1;i++){
console.log("transaction");
var transaction = await web3.eth.getTransactionFromBlock(j , i);
console.log("block :" + j + ", transaction :" + i)
}
}

Can I set Direct Mode with CosmosDB Data API?

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.

How to get available Graph container list in my Cosmos Graph DB?

I am trying to get metadata information of my Cosmos Graph Database. There are a number of Graphs created in this database and I want to list those Graph names.
In the Gremlin API, we have support to connect to any Graph DB container and then we can submit the query as I mentioned in the below code sample. But here we need a {collection} that is our GraphName as well. So somehow we are bound to a particular graph here.
var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,
username: "/dbs/" + database + "/colls/" + collection,
password: authKey);
using (var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
{
gremlinClient.SubmitAsync(query);
}
Is there any way so that we can connect to GraphDB only and get some metadata information ? Such as, in my case, list of available Graphs.
It looks like the Gremlin Client is implemented at a Collection level (i.e. graph) so it won't be possible to enumerate Graphs from one account / database using the gremlin connection.
You can always use the CosmosDB SDK to connect to the account and enumerate the databases/collections and then use the Gremlin Clients to connect to each of them separately.
Install-Package Microsoft.Azure.Cosmos
using (var client = new CosmosClient(endpoint, authKey))
{
var dbIterator = client.GetDatabaseQueryIterator<DatabaseProperties>();
while(dbIterator.HasMoreResults)
{
foreach (var database in await dbIterator.ReadNextAsync())
{
var containerIterator = database.GetContainerQueryIterator<ContainerProperties>();
while (containerIterator.HasMoreResults)
{
foreach (var container in await containerIterator.ReadNextAsync())
{
Console.WriteLine($"{database.Id} - {container.Id}");
}
}
}
}
}

How to share data between two app maker apps?

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;

How to force SSL encryption?

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

Resources