CityofSantaMonica / mds-provider

Python tools for working with MDS Provider data
https://github.com/openmobilityfoundation/mobility-data-specification
MIT License
18 stars 20 forks source link

Parameterize ON CONFLICT DO UPDATE statements #72

Closed thekaveman closed 5 years ago

thekaveman commented 5 years ago

Rather than hard-coding the ON CONFLICT DO UPDATE statements, inject a tuple to generate the statements dynamically.

Breaking Change

Before:

# boolean parameter specified at initialization time
loader = ProviderDataLoader(on_conflict_update=True)

# use the configured loader to load some data
loader.load_trips(data)

or

# initialize without the parameter
loader = ProviderDataLoader()

# boolean parameter used at load time
loader.load_trips(data, on_conflict_update=True)

Now:

# initialize without the parameter
loader = ProviderDataLoader()

# what is in conflict
condition = "(provider_id, trip_id)"

# the column updates to make
# (as a dict)
actions = { "route": "EXCLUDED.route", "start_time": "EXCLUDED.start_time" }
# (or a list)
actions = ["route = EXCLUDED.route", "start_time = EXCLUDED.start_time"]
# (or a simple str)
actions = "route = EXCLUDED.route, start_time = EXCLUDED.start_time"

# tuple parameter used at load time
loader.load_trips(data, on_conflict_update=(condition, actions))