Remove old SQL_ constants. Use the dicts.
This commit is contained in:
		
							parent
							
								
									a8ead9c0c9
								
							
						
					
					
						commit
						e5a316ff9c
					
				
					 2 changed files with 7 additions and 41 deletions
				
			
		|  | @ -144,39 +144,6 @@ for statement in DB_INIT.split(';'): | ||||||
| _sql_dictify = lambda columns: {key:index for (index, key) in enumerate(columns)} | _sql_dictify = lambda columns: {key:index for (index, key) in enumerate(columns)} | ||||||
| SQL_INDEX = {key: _sql_dictify(value) for (key, value) in SQL_COLUMNS.items()} | SQL_INDEX = {key: _sql_dictify(value) for (key, value) in SQL_COLUMNS.items()} | ||||||
| 
 | 
 | ||||||
| def _extract_column_names(table): |  | ||||||
|     statement = DB_INIT.split('CREATE TABLE IF NOT EXISTS %s(' % table)[1] |  | ||||||
|     statement = statement.split(');')[0] |  | ||||||
|     statement = statement.replace('\n', ' ') |  | ||||||
|     columns = statement.split(',') |  | ||||||
|     columns = [column.strip().split(' ')[0] for column in columns] |  | ||||||
|     return columns |  | ||||||
| 
 |  | ||||||
| SQL_LASTID_COLUMNS = _extract_column_names('id_numbers') |  | ||||||
| SQL_ALBUM_DIRECTORY_COLUMNS = _extract_column_names('album_associated_directories') |  | ||||||
| SQL_ALBUM_COLUMNS = _extract_column_names('albums') |  | ||||||
| SQL_BOOKMARK_COLUMNS = _extract_column_names('bookmarks') |  | ||||||
| SQL_PHOTO_COLUMNS = _extract_column_names('photos') |  | ||||||
| SQL_TAG_COLUMNS = _extract_column_names('tags') |  | ||||||
| SQL_SYN_COLUMNS = _extract_column_names('tag_synonyms') |  | ||||||
| SQL_ALBUMGROUP_COLUMNS = _extract_column_names('album_group_rel') |  | ||||||
| SQL_ALBUMPHOTO_COLUMNS = _extract_column_names('album_photo_rel') |  | ||||||
| SQL_PHOTOTAG_COLUMNS = _extract_column_names('photo_tag_rel') |  | ||||||
| SQL_TAGGROUP_COLUMNS = _extract_column_names('tag_group_rel') |  | ||||||
| SQL_USER_COLUMNS = _extract_column_names('users') |  | ||||||
| 
 |  | ||||||
| SQL_ALBUM = _sql_dictify(SQL_ALBUM_COLUMNS) |  | ||||||
| SQL_ALBUM_DIRECTORY = _sql_dictify(SQL_ALBUM_DIRECTORY_COLUMNS) |  | ||||||
| SQL_ALBUMGROUP = _sql_dictify(SQL_ALBUMGROUP_COLUMNS) |  | ||||||
| SQL_BOOKMARK = _sql_dictify(SQL_BOOKMARK_COLUMNS) |  | ||||||
| SQL_ALBUMPHOTO = _sql_dictify(SQL_ALBUMPHOTO_COLUMNS) |  | ||||||
| SQL_LASTID = _sql_dictify(SQL_LASTID_COLUMNS) |  | ||||||
| SQL_PHOTO = _sql_dictify(SQL_PHOTO_COLUMNS) |  | ||||||
| SQL_PHOTOTAG = _sql_dictify(SQL_PHOTOTAG_COLUMNS) |  | ||||||
| SQL_SYN = _sql_dictify(SQL_SYN_COLUMNS) |  | ||||||
| SQL_TAG = _sql_dictify(SQL_TAG_COLUMNS) |  | ||||||
| SQL_TAGGROUP = _sql_dictify(SQL_TAGGROUP_COLUMNS) |  | ||||||
| SQL_USER = _sql_dictify(SQL_USER_COLUMNS) |  | ||||||
| 
 | 
 | ||||||
| ALLOWED_ORDERBY_COLUMNS = [ | ALLOWED_ORDERBY_COLUMNS = [ | ||||||
|     'extension', |     'extension', | ||||||
|  |  | ||||||
|  | @ -10,7 +10,6 @@ from . import helpers | ||||||
| from voussoirkit import bytestring | from voussoirkit import bytestring | ||||||
| from voussoirkit import pathclass | from voussoirkit import pathclass | ||||||
| from voussoirkit import spinal | from voussoirkit import spinal | ||||||
| from voussoirkit import sqlhelpers |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ObjectBase: | class ObjectBase: | ||||||
|  | @ -211,13 +210,13 @@ class GroupableMixin: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Album(ObjectBase, GroupableMixin): | class Album(ObjectBase, GroupableMixin): | ||||||
|     group_sql_index = constants.SQL_ALBUMGROUP |  | ||||||
|     group_table = 'album_group_rel' |     group_table = 'album_group_rel' | ||||||
|  |     group_sql_index = constants.SQL_INDEX[group_table] | ||||||
| 
 | 
 | ||||||
|     def __init__(self, photodb, db_row): |     def __init__(self, photodb, db_row): | ||||||
|         super().__init__(photodb) |         super().__init__(photodb) | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_ALBUM_COLUMNS, db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['albums'], db_row)) | ||||||
| 
 | 
 | ||||||
|         self.id = db_row['id'] |         self.id = db_row['id'] | ||||||
|         self.title = db_row['title'] or '' |         self.title = db_row['title'] or '' | ||||||
|  | @ -481,7 +480,7 @@ class Bookmark(ObjectBase): | ||||||
|     def __init__(self, photodb, db_row): |     def __init__(self, photodb, db_row): | ||||||
|         super().__init__(photodb) |         super().__init__(photodb) | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_BOOKMARK_COLUMNS, db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['bookmarks'], db_row)) | ||||||
| 
 | 
 | ||||||
|         self.id = db_row['id'] |         self.id = db_row['id'] | ||||||
|         self.title = db_row['title'] |         self.title = db_row['title'] | ||||||
|  | @ -537,7 +536,7 @@ class Photo(ObjectBase): | ||||||
|     def __init__(self, photodb, db_row): |     def __init__(self, photodb, db_row): | ||||||
|         super().__init__(photodb) |         super().__init__(photodb) | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_PHOTO_COLUMNS, db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['photos'], db_row)) | ||||||
| 
 | 
 | ||||||
|         self.real_filepath = helpers.remove_path_badchars(db_row['filepath'], allowed=':\\/') |         self.real_filepath = helpers.remove_path_badchars(db_row['filepath'], allowed=':\\/') | ||||||
|         self.real_path = pathclass.Path(self.real_filepath) |         self.real_path = pathclass.Path(self.real_filepath) | ||||||
|  | @ -1041,13 +1040,13 @@ class Tag(ObjectBase, GroupableMixin): | ||||||
|     ''' |     ''' | ||||||
|     A Tag, which can be applied to Photos for organization. |     A Tag, which can be applied to Photos for organization. | ||||||
|     ''' |     ''' | ||||||
|     group_sql_index = constants.SQL_TAGGROUP |  | ||||||
|     group_table = 'tag_group_rel' |     group_table = 'tag_group_rel' | ||||||
|  |     group_sql_index = constants.SQL_INDEX[group_table] | ||||||
| 
 | 
 | ||||||
|     def __init__(self, photodb, db_row): |     def __init__(self, photodb, db_row): | ||||||
|         super().__init__(photodb) |         super().__init__(photodb) | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_TAG_COLUMNS, db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['tags'], db_row)) | ||||||
|         self.id = db_row['id'] |         self.id = db_row['id'] | ||||||
|         self.name = db_row['name'] |         self.name = db_row['name'] | ||||||
|         self.description = db_row['description'] or '' |         self.description = db_row['description'] or '' | ||||||
|  | @ -1318,7 +1317,7 @@ class User(ObjectBase): | ||||||
|     def __init__(self, photodb, db_row): |     def __init__(self, photodb, db_row): | ||||||
|         super().__init__(photodb) |         super().__init__(photodb) | ||||||
|         if isinstance(db_row, (list, tuple)): |         if isinstance(db_row, (list, tuple)): | ||||||
|             db_row = dict(zip(constants.SQL_USER_COLUMNS, db_row)) |             db_row = dict(zip(constants.SQL_COLUMNS['users'], db_row)) | ||||||
|         self.id = db_row['id'] |         self.id = db_row['id'] | ||||||
|         self.username = db_row['username'] |         self.username = db_row['username'] | ||||||
|         self.created = db_row['created'] |         self.created = db_row['created'] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue