Deleting user-defined functions
How can i delete user-defined functions ?
db.function('add2', (a, b) => a + b);
for example, here i defined the function add2, if i wanted to delete it in postgresql i would do
DROP ROUTINE IF EXISTS add2
but this is not supported by sqlite3/better-sqlite3.
So I was wondering if there is a sqlite statement for that or a pragma, and if not when closing and reopening the database the functions are deleted, therefore they are not saved in the database, so, I was wondering if you could do something at the C++ level.
What's your use case? I don't understand what you're trying to achieve.
You can do this to achieve basically the same:
// "remove "the add2 function
db.function('add2', () => throw new Error('not implemented'));
Or as you said open a new connection. Or have two connections, one with your custom functions and one without.
What's your use case? I don't understand what you're trying to achieve.
I am going to have dynamically generated functions, but when I stop using a certain function I would like to delete it so that it does not occupy memory.
db.function('add2', () => throw new Error('not implemented'));
this isn't what i want
Sounds like a valid feature request, the SQLite docs say:
To delete an existing SQL function or aggregate, pass NULL pointers for all three function callbacks.
but currently better-sqlite3 always expects a function. I think the current API could be extended in a backwards compatible way to allow db.function('add2', null) to explicitly remove a function.
sounds great, I'll be waiting for it