Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSERT many functionality #4644

Merged
merged 14 commits into from Feb 20, 2019

fix pg

  • Loading branch information...
hawkowl committed Feb 14, 2019
commit 254b60cf62f219970bfd76638d093dfa912d894b
@@ -321,34 +321,34 @@ class UpsertManyTests(unittest.HomeserverTestCase):
def prepare(self, reactor, clock, hs):
self.storage = hs.get_datastore()

self.table_name = "table_" + hs.get_secrets().token_hex()
self.table_name = "table_" + hs.get_secrets().token_hex(6)
self.get_success(
self.storage._execute(
self.storage.runInteraction(
"create",
None,
"CREATE TABLE %s (id INTEGER, user TEXT, value TEXT)"
lambda x, *a: x.execute(*a),
"CREATE TABLE %s (id INTEGER, username TEXT, value TEXT)"
% (self.table_name,),
)
)
self.get_success(
self.storage._execute(
self.storage.runInteraction(
"index",
None,
"CREATE UNIQUE INDEX %s_index ON %s(id, user)"
lambda x, *a: x.execute(*a),
"CREATE UNIQUE INDEX %sindex ON %s(id, username)"
% (self.table_name, self.table_name),
)
)

def _dump_to_tuple(self, res):
for i in res:
yield (i["id"], i["user"], i["value"])
yield (i["id"], i["username"], i["value"])

def test_upsert_many(self):
"""
Upsert_many will perform the upsert operation across a batch of data.
"""
# Add some data to an empty table
key_names = ["id", "user"]
key_names = ["id", "username"]
value_names = ["value"]
key_values = [[1, "user1"], [2, "user2"]]
value_values = [["hello"], ["there"]]
@@ -367,7 +367,9 @@ def test_upsert_many(self):

# Check results are what we expect
res = self.get_success(
self.storage._simple_select_list(self.table_name, None, ["id, user, value"])
self.storage._simple_select_list(
self.table_name, None, ["id, username, value"]
)
)
self.assertEqual(
set(self._dump_to_tuple(res)),
@@ -392,7 +394,9 @@ def test_upsert_many(self):

# Check results are what we expect
res = self.get_success(
self.storage._simple_select_list(self.table_name, None, ["id, user, value"])
self.storage._simple_select_list(
self.table_name, None, ["id, username, value"]
)
)
self.assertEqual(
set(self._dump_to_tuple(res)),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.