Skip to content

Commit

Permalink
Snowflake example (#16)
Browse files Browse the repository at this point in the history
* Snowflake example

Snowflake example

* Gears execution for WB with snowflake

RedisGears Write-Behind recipe for snowflake database
  • Loading branch information
viragtripathi authored Apr 15, 2020
1 parent 65e0787 commit f9985ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/snowflake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Running the recipe
You can use [this utility](https://github.com/RedisGears/RedisGears/blob/master/recipes/gears.py) to send a RedisGears Write-Behind or Write-Through recipe for execution. For example, run this repository's [example.py recipe](https://github.com/rgsync/examples/snowflake/example.py) and install its dependencies with the following command:

```bash
python gears.py --host <host> --port <port> --password <password> examples/snowflake/example.py REQUIREMENTS rgsync snowflake-sqlalchemy
```
39 changes: 39 additions & 0 deletions examples/snowflake/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from rgsync import RGWriteBehind, RGWriteThrough
from rgsync.Connectors import SnowflakeSqlConnector, SnowflakeSqlConnection

'''
Create Snowflake connection object
The connection object will be translated to snowflake://<user>:<password>@<account>/<db>
'''
connection = SnowflakeSqlConnection('<user>', '<password>', '<account>', '<db>')

'''
Create Snowflake person1 connector
persons - Snowflake table to put the data
id - primary key
'''
personsConnector = SnowflakeSqlConnector(connection, 'person1', 'id')

personsMappings = {
'first_name':'first',
'last_name':'last',
'age':'age'
}

RGWriteBehind(GB, keysPrefix='person', mappings=personsMappings, connector=personsConnector, name='PersonsWriteBehind', version='99.99.99')

RGWriteThrough(GB, keysPrefix='__', mappings=personsMappings, connector=personsConnector, name='PersonsWriteThrough', version='99.99.99')

'''
Create Snowflake car connector
car - Snowflake table to put the data
license - primary key
'''
carsConnector = SnowflakeSqlConnector(connection, 'car', 'license')

carsMappings = {
'license':'license',
'color':'color'
}

RGWriteBehind(GB, keysPrefix='car', mappings=carsMappings, connector=carsConnector, name='CarsWriteBehind', version='99.99.99')

0 comments on commit f9985ae

Please sign in to comment.