Integrate voussoirkit sqlhelpers.
https://github.com/voussoir/else/tree/master/SQLHelpers
This commit is contained in:
parent
6f371701e4
commit
b5902ba4f1
4 changed files with 9 additions and 37 deletions
|
@ -51,36 +51,6 @@ def album_zip_filenames(album, recursive=True):
|
|||
|
||||
return arcnames
|
||||
|
||||
def binding_filler(column_names, values, require_all=True):
|
||||
'''
|
||||
Manually aligning question marks and bindings is annoying.
|
||||
Given the table's column names and a dictionary of {column: value},
|
||||
return the question marks and the list of bindings in the right order.
|
||||
|
||||
require_all:
|
||||
If `values` does not contain one of the column names, should we raise
|
||||
an exception?
|
||||
Otherwise, that column will simply receive None.
|
||||
|
||||
Ex:
|
||||
column_names=['id', 'name', 'score'],
|
||||
values={'score': 20, 'id': '1111', 'name': 'James'}
|
||||
->
|
||||
returns ('?, ?, ?', ['1111', 'James', 20])
|
||||
'''
|
||||
values = values.copy()
|
||||
for column in column_names:
|
||||
if column in values:
|
||||
continue
|
||||
if require_all:
|
||||
raise ValueError('Missing column "%s"' % column)
|
||||
else:
|
||||
values.setdefault(column, None)
|
||||
qmarks = '?' * len(column_names)
|
||||
qmarks = ', '.join(qmarks)
|
||||
bindings = [values[column] for column in column_names]
|
||||
return (qmarks, bindings)
|
||||
|
||||
def checkerboard_image(color_1, color_2, image_size, checker_size):
|
||||
'''
|
||||
Generate a PIL Image with a checkerboard pattern.
|
||||
|
|
|
@ -10,6 +10,7 @@ from . import helpers
|
|||
from voussoirkit import bytestring
|
||||
from voussoirkit import pathclass
|
||||
from voussoirkit import spinal
|
||||
from voussoirkit import sqlhelpers
|
||||
|
||||
|
||||
class ObjectBase:
|
||||
|
@ -284,7 +285,7 @@ class Album(ObjectBase, GroupableMixin):
|
|||
'albumid': self.id,
|
||||
'directory': filepath.absolute_path,
|
||||
}
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_ALBUM_DIRECTORY_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_ALBUM_DIRECTORY_COLUMNS, data)
|
||||
query = 'INSERT INTO album_associated_directories VALUES(%s)' % qmarks
|
||||
cur = self.photodb.sql.cursor()
|
||||
cur.execute(query, bindings)
|
||||
|
|
|
@ -21,6 +21,7 @@ from voussoirkit import cacheclass
|
|||
from voussoirkit import expressionmatch
|
||||
from voussoirkit import pathclass
|
||||
from voussoirkit import spinal
|
||||
from voussoirkit import sqlhelpers
|
||||
|
||||
|
||||
logging.basicConfig()
|
||||
|
@ -247,7 +248,7 @@ class PDBAlbumMixin:
|
|||
'description': description,
|
||||
}
|
||||
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_ALBUM_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_ALBUM_COLUMNS, data)
|
||||
query = 'INSERT INTO albums VALUES(%s)' % qmarks
|
||||
|
||||
cur.execute(query, bindings)
|
||||
|
@ -297,7 +298,7 @@ class PDBBookmarkMixin:
|
|||
'url': url,
|
||||
}
|
||||
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_BOOKMARK_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_BOOKMARK_COLUMNS, data)
|
||||
query = 'INSERT INTO bookmarks VALUES(%s)' % qmarks
|
||||
cur = self.sql.cursor()
|
||||
cur.execute(query, bindings)
|
||||
|
@ -409,7 +410,7 @@ class PDBPhotoMixin:
|
|||
'thumbnail': None,
|
||||
}
|
||||
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_PHOTO_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_PHOTO_COLUMNS, data)
|
||||
query = 'INSERT INTO photos VALUES(%s)' % qmarks
|
||||
cur = self.sql.cursor()
|
||||
cur.execute(query, bindings)
|
||||
|
@ -918,7 +919,7 @@ class PDBTagMixin:
|
|||
'name': tagname,
|
||||
'description': description,
|
||||
}
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_TAG_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_TAG_COLUMNS, data)
|
||||
query = 'INSERT INTO tags VALUES(%s)' % qmarks
|
||||
cur.execute(query, bindings)
|
||||
if commit:
|
||||
|
@ -1086,7 +1087,7 @@ class PDBUserMixin:
|
|||
'created': created,
|
||||
}
|
||||
|
||||
(qmarks, bindings) = helpers.binding_filler(constants.SQL_USER_COLUMNS, data)
|
||||
(qmarks, bindings) = sqlhelpers.insert_filler(constants.SQL_USER_COLUMNS, data)
|
||||
query = 'INSERT INTO users VALUES(%s)' % qmarks
|
||||
cur = self.sql.cursor()
|
||||
cur.execute(query, bindings)
|
||||
|
|
|
@ -2,6 +2,6 @@ bcrypt
|
|||
flask
|
||||
gevent
|
||||
pillow
|
||||
voussoirkit
|
||||
voussoirkit>=0.0.18
|
||||
zipstream
|
||||
git+https://github.com/senko/python-video-converter.git
|
||||
|
|
Loading…
Reference in a new issue