summaryrefslogtreecommitdiff
path: root/megapixels/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'megapixels/app/models')
-rw-r--r--megapixels/app/models/sql_factory.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/megapixels/app/models/sql_factory.py b/megapixels/app/models/sql_factory.py
index 9a44941b..da95b539 100644
--- a/megapixels/app/models/sql_factory.py
+++ b/megapixels/app/models/sql_factory.py
@@ -10,7 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base
from app.utils.file_utils import load_recipe, load_csv_safe
from app.settings import app_cfg as cfg
-connection_url = "mysql+mysqldb://{}:{}@{}/{}".format(
+connection_url = "mysql+mysqlconnector://{}:{}@{}/{}?charset=utf8mb4".format(
os.getenv("DB_USER"),
os.getenv("DB_PASS"),
os.getenv("DB_HOST"),
@@ -35,7 +35,12 @@ def load_sql_datasets(replace=False, base_model=None):
global datasets, loaded, Session
if loaded:
return datasets
- engine = create_engine(connection_url)
+ engine = create_engine(connection_url, encoding="utf-8")
+ # db.set_character_set('utf8')
+ # dbc = db.cursor()
+ # dbc.execute('SET NAMES utf8;')
+ # dbc.execute('SET CHARACTER SET utf8;')
+ # dbc.execute('SET character_set_connection=utf8;')
Session = sessionmaker(bind=engine)
for path in glob.iglob(os.path.join(cfg.DIR_FAISS_METADATA, "*")):
dataset = load_sql_dataset(path, replace, engine, base_model)
@@ -92,13 +97,27 @@ class SqlDataset:
'pose': self.select('pose', id),
}
+ def search_name(self, q):
+ table = self.get_table('identity_meta')
+ uuid_table = self.get_table('uuids')
+
+ identity = table.query.filter(table.fullname.like(q)).order_by(table.fullname.desc()).limit(30)
+ identities = []
+ for row in identity:
+ uuid = uuid_table.query.filter(uuid_table.id == row.image_id).first()
+ identities.append({
+ 'uuid': uuid.toJSON(),
+ 'identity': row.toJSON(),
+ })
+ return identities
+
def select(self, table, id):
table = self.get_table(table)
if not table:
return None
session = Session()
# for obj in session.query(table).filter_by(id=id):
- print(table)
+ # print(table)
obj = session.query(table).filter(table.id == id).first()
session.close()
return obj.toJSON()
@@ -125,7 +144,7 @@ class SqlDataset:
class UUID(self.base_model):
__tablename__ = self.name + "_uuid"
id = Column(Integer, primary_key=True)
- uuid = Column(String(36), nullable=False)
+ uuid = Column(String(36, convert_unicode=True), nullable=False)
def toJSON(self):
return {
'id': self.id,
@@ -167,9 +186,9 @@ class SqlDataset:
class Identity(self.base_model):
__tablename__ = self.name + "_identity"
id = Column(Integer, primary_key=True)
- fullname = Column(String(36), nullable=False)
- description = Column(String(36), nullable=False)
- gender = Column(String(1), nullable=False)
+ fullname = Column(String(36, convert_unicode=True), nullable=False)
+ description = Column(String(36, convert_unicode=True), nullable=False)
+ gender = Column(String(1, convert_unicode=True), nullable=False)
images = Column(Integer, nullable=False)
image_id = Column(Integer, nullable=False)
def toJSON(self):