diff --git a/.gitignore b/.gitignore index 6a014f5..7e00121 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .sass-cache .DS_Store +.my.cnf # github premade rules *.py[cod] diff --git a/bitshift/database.py b/bitshift/database.py index 36b984e..647fe55 100644 --- a/bitshift/database.py +++ b/bitshift/database.py @@ -3,19 +3,18 @@ Module with classes and functions to handle communication with the MySQL database backend, which manages the search index. """ +import mmh3 import oursql class Database(object): """Represents the MySQL database.""" def __init__(self): - pass + self._connect() def _connect(self): - pass - - def _create(self): - pass + """Establish a connection to the database.""" + self._conn = oursql.connect() def search(self, query): """ @@ -36,4 +35,5 @@ class Database(object): :param codelet: The codelet to insert. :type codelet: :py:class:`.Codelet` """ + # code_hash = mmh3.hash64(codelet.code)[0] pass diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..3cb915c --- /dev/null +++ b/schema.sql @@ -0,0 +1,23 @@ +CREATE DATABASE bitshift DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; +USE `bitshift`; + +CREATE TABLE codelets ( + `codelet_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, + `codelet_name` VARCHAR(512) NOT NULL, + `codelet_code_id` BIGINT UNSIGNED NOT NULL, + `codelet_lang` SMALLINT UNSIGNED DEFAULT NULL, + `codelet_origin` TINYINT UNSIGNED DEFAULT NULL, + `codelet_url` VARCHAR(512) NOT NULL, + `codelet_date_created` DATETIME DEFAULT NULL, + `codelet_date_modified` DATETIME DEFAULT NULL, + PRIMARY KEY (`codelet_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +CREATE TABLE code ( + `code_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, + `code_hash` BIGINT NOT NULL, + `code_code` MEDIUMTEXT NOT NULL, + PRIMARY KEY (`code_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- separate tables: authors, symbols, caches, search indices diff --git a/setup.py b/setup.py index 5fa1189..97441b7 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,9 @@ setup( name = "bitshift", version = "0.1", packages = find_packages(), - install_requires = ["Flask>=0.10.1", "pygments>=1.6", "requests>=2.2.0", - "BeautifulSoup>=3.2.1", "oursql>=0.9.3.1"], + install_requires = [ + "Flask>=0.10.1", "pygments>=1.6", "requests>=2.2.0", + "BeautifulSoup>=3.2.1", "oursql>=0.9.3.1", "mmh3>=2.3"], author = "Benjamin Attal, Ben Kurtovic, Severyn Kozak", license = "MIT", url = "https://github.com/earwig/bitshift"