mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 17:34:32 +02:00
@db.register_function decorator, closes #162
This commit is contained in:
parent
ef882986d0
commit
482477585a
3 changed files with 44 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import contextlib
|
|||
import datetime
|
||||
import decimal
|
||||
import hashlib
|
||||
import inspect
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
|
|
@ -143,6 +144,11 @@ class Database:
|
|||
def __repr__(self):
|
||||
return "<Database {}>".format(self.conn)
|
||||
|
||||
def register_function(self, fn):
|
||||
name = fn.__name__
|
||||
arity = len(inspect.signature(fn).parameters)
|
||||
self.conn.create_function(name, arity, fn)
|
||||
|
||||
def execute(self, sql, parameters=None):
|
||||
if self._tracer:
|
||||
self._tracer(sql, parameters)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue