@db.register_function(..., replace=True), closes #199

This commit is contained in:
Simon Willison 2020-11-06 07:53:22 -08:00
commit 27b67f1cae
4 changed files with 38 additions and 2 deletions

View file

@ -44,3 +44,25 @@ def test_register_function_deterministic_registered(fresh_db):
fresh_db.conn.create_function.assert_called_with(
"to_lower_2", 1, to_lower_2, deterministic=True
)
def test_register_function_replace(fresh_db):
@fresh_db.register_function()
def one():
return "one"
assert "one" == fresh_db.execute("select one()").fetchone()[0]
# This will fail to replace the function:
@fresh_db.register_function()
def one():
return "two"
assert "one" == fresh_db.execute("select one()").fetchone()[0]
# This will replace it
@fresh_db.register_function(replace=True)
def one():
return "two"
assert "two" == fresh_db.execute("select one()").fetchone()[0]