Model sync from MySQL to Snowflake
Before getting started make sure to set your Polytomic API key as an environment variable:
This example tutorial will cover three steps:
- Connecting to MySQL.
- Creating a model.
- Creating a sync to Snowflake.
1. Create a Connection
The following request will create a MySQL connection. The configuration for each type of connection can be found at the connection configuration page in our documentation.
cURL
Python
Typescript
Go
2. Create a Model
Next we’ll create a model of a “customers” table using the MySQL connection we just created.
Connections can be enumerated using the source endpoint. This next call will show us all available tables on the connection we just created:
cURL
Python
Typescript
Go
The response will look like:
Sources
Each source level can be drilled down by using query parameters. e.g. ?table=company.accounts
. In this case; however, tables requires_one_of property is null so we don’t need to drill down.
Finally, we can create a model using the company.customers table like we mentioned above:
cURL
Python
Typescript
Go
Important: Make sure to replace YOUR-CONNECTION-ID
with the returned connection ID.
3. Create a sync
Next we’ll create a sync using the customer model we created above. We’ll also create an additional connection that we will use as the target.
Create a target
Here, we’ll create a Snowflake connection as our target.
cURL
Python
Typescript
Go
Enumerate target
In the same way sources can be enumerated, so can targets.
cURL
Python
Typescript
Go
The response will look like:
Next, we can drill down using the requires_one_of
field recursively. For example:
cURL
Python
Typescript
Go
The response will look like:
Notice, the schema also requires a table. We can enumerate those by adding to the query parameters.
cURL
Python
Typescript
Go
The response will look like:
Query target fields
The last step in enumerating a target for a sync is querying the available fields. To do this, we can POST a fields query on the target resource.
cURL
Python
Typescript
Go
This response will show the available syncs modes as well as the fields and their associated metadata. For example:
Setup sync mapping
Finally, we can set up a mapping of fields from the model we created above and the target as seen below: