소스 검색

Move database stuff to a subpackage; updates.

tags/v1.0^2
Ben Kurtovic 10 년 전
부모
커밋
54bca5894f
2개의 변경된 파일34개의 추가작업 그리고 5개의 파일을 삭제
  1. +34
    -5
      bitshift/database/__init__.py
  2. +0
    -0
      bitshift/database/schema.sql

bitshift/database.py → bitshift/database/__init__.py 파일 보기

@@ -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 파일 보기


불러오는 중...
취소
저장