Bläddra i källkod

Move database stuff to a subpackage; updates.

tags/v1.0^2
Ben Kurtovic 10 år sedan
förälder
incheckning
54bca5894f
2 ändrade filer med 34 tillägg och 5 borttagningar
  1. +34
    -5
      bitshift/database/__init__.py
  2. +0
    -0
      bitshift/database/schema.sql

bitshift/database.py → bitshift/database/__init__.py Visa fil

@@ -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.
"""

import os

import mmh3
import oursql

# from .languages import ...
# from ..languages import ...

__all__ = ["Database"]

class Database(object):
"""Represents the MySQL database."""
@@ -16,7 +20,9 @@ class Database(object):

def _connect(self):
"""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):
"""
@@ -48,5 +54,28 @@ class Database(object):
:param codelet: The codelet to insert.
: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]

schema.sql → bitshift/database/schema.sql Visa fil


Laddar…
Avbryt
Spara