Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Feb 21, 2016
1 parent 98e19e1 commit e11728a
Show file tree
Hide file tree
Showing 12 changed files with 2,209 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
/.idea
convert_readme.sh
desktop.ini
README.md
*.ipynb
readme_converter.py
README_HEADER.rst
upgrade.sh
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: python

env:
- TOXENV=py25
- TOXENV=py26
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34

os:
- linux

install:
- pip install tox
- pip install coveralls

script:
- tox
- python setup.py test --addopts "-v --cov simplesqlite --cov-report term-missing"

after_success:
- coveralls
11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include LICENSE
include README.rst
include setup.cfg
include tox.ini
include requirements.txt
include test_requirements.txt
include docs_requirements.txt
recursive-include test *

global-exclude __pycache__/*
global-exclude *.pyc
194 changes: 194 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
**SimpleSQLite**

.. contents:: Table of contents
:backlinks: top
:local:

About
=====

SimpleSQLite is a python library to simplify the table creation and data
insertion in SQLite database.

Feature
=======

- Automatic table creation from data
- Support various data type for insertion : dictionary, namedtuple,
list and tuple

Usage
=====

Create table
------------

Sample
~~~~~~

.. code:: python
from simplesqlite import SimpleSQLite
con = SimpleSQLite("sample.sqlite")
# create table -----
data_matrix = [
[1, 1.1, "aaa", 1, 1],
[2, 2.2, "bbb", 2.2, 2.2],
[3, 3.3, "ccc", 3, "ccc"],
]
con.create_table_with_data(
table_name="sample_table",
attribute_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
data_matrix=data_matrix,
index_attribute_list=["attr_a"]
)
# display values -----
result = con.select(select="*", table="sample_table")
for record in result.fetchall():
print record
# display type for each column -----
query = "SELECT DISTINCT TYPEOF(attr_a),TYPEOF(attr_b),TYPEOF(attr_c),TYPEOF(attr_d),TYPEOF(attr_e) FROM sample_table"
result = con.execute_query(query)
print result.fetchall()
Output
~~~~~~

.. code:: console
(1, 1.1, u'aaa', 1.0, u'1')
(2, 2.2, u'bbb', 2.2, u'2.2')
(3, 3.3, u'ccc', 3.0, u'ccc')
[(u'integer', u'real', u'text', u'real', u'text')]
insert
------

Dictionary
~~~~~~~~~~

.. code:: python
con.insert(
"sample_table",
{
"attr_a": 4,
"attr_b": 4.4,
"attr_c": "ddd",
"attr_d": 4.44,
"attr_e": "hoge",
}
)
con.insert_many(
"sample_table",
[
{
"attr_a": 5,
"attr_b": 5.5,
"attr_c": "eee",
"attr_d": 5.55,
"attr_e": "foo",
},
{
"attr_a": 6,
"attr_c": "fff",
},
]
)
result = con.select(select="*", table="sample_table")
for record in result.fetchall():
print record
.. code:: console
(1, 1.1, u'aaa', 1.0, u'1')
(2, 2.2, u'bbb', 2.2, u'2.2')
(3, 3.3, u'ccc', 3.0, u'ccc')
(4, 4.4, u'ddd', 4.44, u'hoge')
(5, 5.5, u'eee', 5.55, u'foo')
(6, u'NULL', u'fff', u'NULL', u'NULL')
list/tuple/namedtuple
~~~~~~~~~~~~~~~~~~~~~

.. code:: python
from collections import namedtuple
SampleTuple = namedtuple(
"SampleTuple", "attr_a attr_b attr_c attr_d attr_e")
con.insert("sample_table", [7, 7.7, "fff", 7.77, "bar"])
con.insert_many(
"sample_table",
[
(8, 8.8, "ggg", 8.88, "foobar"),
SampleTuple(9, 9.9, "ggg", 9.99, "hogehoge"),
]
)
result = con.select(select="*", table="sample_table")
for record in result.fetchall():
print record
.. code:: console
(1, 1.1, u'aaa', 1.0, u'1')
(2, 2.2, u'bbb', 2.2, u'2.2')
(3, 3.3, u'ccc', 3.0, u'ccc')
(4, 4.4, u'ddd', 4.44, u'hoge')
(5, 5.5, u'eee', 5.55, u'foo')
(6, u'NULL', u'fff', u'NULL', u'NULL')
(7, 7.7, u'fff', 7.77, u'bar')
(8, 8.8, u'ggg', 8.88, u'foobar')
(9, 9.9, u'ggg', 9.99, u'hogehoge')
Misc
----

In default ``__table_configuration__`` table will automatically
create/insert-data each time of table creation.
``__table_configuration__`` table contains each table information, such
as the value type of columns, columns has index or not.

Sample value of ``__table_configuration__`` table is as follows.

+-----------------+-------------------+---------------+--------------+
| table\_name | attribute\_name | value\_type | has\_index |
+=================+===================+===============+==============+
| sample\_table | attr\_a | INTEGER | 1 |
+-----------------+-------------------+---------------+--------------+
| sample\_table | attr\_b | REAL | 0 |
+-----------------+-------------------+---------------+--------------+
| sample\_table | attr\_c | TEXT | 0 |
+-----------------+-------------------+---------------+--------------+
| sample\_table | attr\_d | REAL | 0 |
+-----------------+-------------------+---------------+--------------+
| sample\_table | attr\_e | TEXT | 0 |
+-----------------+-------------------+---------------+--------------+

Dependencies
============

Python 2.5+ or 3.3+

- `DataPropery <https://github.com/thombashi/DataProperty>`__
- Used to extract data types.
- `six <https://pypi.python.org/pypi/six/>`__

Test dependencies
-----------------

- `pytest <https://pypi.python.org/pypi/pytest>`__
- `pytest-runner <https://pypi.python.org/pypi/pytest-runner>`__
- `tox <https://pypi.python.org/pypi/tox>`__

Documentation
=============

Under construction
1 change: 1 addition & 0 deletions docs_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sphinx_rtd_theme
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DataProperty
six<=1.8.0
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[aliases]
test=pytest

[wheel]
universal = 1
46 changes: 46 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from __future__ import with_statement
import setuptools


with open("README.rst") as fp:
long_description = fp.read()

with open("requirements.txt") as f:
install_requires = [line.strip() for line in f if line.strip()]

with open("test_requirements.txt") as f:
tests_require = [line.strip() for line in f if line.strip()]

setuptools.setup(
name="SimpleSQLite",
version="0.1.0",
author="Tsuyoshi Hombashi",
author_email="gogogo.vm@gmail.com",
url="https://github.com/thombashi/SimpleSQLite",
description="Python library to simplify the table creation/insertion in SQLite database",
long_description=long_description,
license="MIT License",
include_package_data=True,
packages=setuptools.find_packages(exclude=['test*']),
install_requires=install_requires,
setup_requires=["pytest-runner"],
tests_require=tests_require,
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.5",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Topic :: Database",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)

0 comments on commit e11728a

Please sign in to comment.