|
@@ -1,12 +1,16 @@ |
|
|
""" |
|
|
""" |
|
|
Module with classes and functions to handle communication with the MySQL |
|
|
|
|
|
|
|
|
Subpackage with classes and functions to handle communication with the MySQL |
|
|
database backend, which manages the search index. |
|
|
database backend, which manages the search index. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
|
import mmh3 |
|
|
import mmh3 |
|
|
import oursql |
|
|
import oursql |
|
|
|
|
|
|
|
|
# from .languages import ... |
|
|
|
|
|
|
|
|
# from ..languages import ... |
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["Database"] |
|
|
|
|
|
|
|
|
class Database(object): |
|
|
class Database(object): |
|
|
"""Represents the MySQL database.""" |
|
|
"""Represents the MySQL database.""" |
|
@@ -16,7 +20,9 @@ class Database(object): |
|
|
|
|
|
|
|
|
def _connect(self): |
|
|
def _connect(self): |
|
|
"""Establish a connection to the database.""" |
|
|
"""Establish a connection to the database.""" |
|
|
self._conn = oursql.connect() |
|
|
|
|
|
|
|
|
default_file = os.path.join(os.path.dirname(__file__), ".my.cnf") |
|
|
|
|
|
self._conn = oursql.connect(read_default_file=default_file, |
|
|
|
|
|
autoping=True, autoreconnect=True) |
|
|
|
|
|
|
|
|
def search(self, query, page=1): |
|
|
def search(self, query, page=1): |
|
|
""" |
|
|
""" |
|
@@ -48,5 +54,28 @@ class Database(object): |
|
|
:param codelet: The codelet to insert. |
|
|
:param codelet: The codelet to insert. |
|
|
:type codelet: :py:class:`.Codelet` |
|
|
:type codelet: :py:class:`.Codelet` |
|
|
""" |
|
|
""" |
|
|
# code_hash = mmh3.hash64(codelet.code.encode("utf8"))[0] |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
query = "INSERT INTO codelets VALUES (?, ?, ?, ?, ?, ?, ?, ?)" |
|
|
|
|
|
|
|
|
|
|
|
cursor.execute(query, ()) |
|
|
|
|
|
|
|
|
|
|
|
# codelet_id -- auto_increment used here |
|
|
|
|
|
codelet_name |
|
|
|
|
|
codelet_code_id |
|
|
|
|
|
codelet_lang |
|
|
|
|
|
codelet_origin |
|
|
|
|
|
codelet_url |
|
|
|
|
|
codelet_rank |
|
|
|
|
|
codelet_date_created |
|
|
|
|
|
codelet_date_modified |
|
|
|
|
|
|
|
|
|
|
|
# codelet fields |
|
|
|
|
|
codelet.name |
|
|
|
|
|
codelet.code |
|
|
|
|
|
codelet.filename |
|
|
|
|
|
codelet.language |
|
|
|
|
|
codelet.authors |
|
|
|
|
|
codelet.code_url |
|
|
|
|
|
codelet.date_created |
|
|
|
|
|
codelet.date_modified |
|
|
|
|
|
|
|
|
|
|
|
code_hash = mmh3.hash64(codelet.code.encode("utf8"))[0] |