Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #35

Merged
merged 5 commits into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
.. |timedelta| replace:: :py:class:`datetime.timedelta`

.. |TableData| replace:: :py:class:`~simplesqlite.loader.data.TableData`
.. |SimpleSQLite| replace:: :py:class:`~simplesqlite.SimpleSQLite`
"""

rp_module = u"""
Expand Down
50 changes: 43 additions & 7 deletions docs/pages/examples/in_memory_database.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
Make an in-memory database
--------------------------

:py:func:`~simplesqlite.connect_sqlite_db_mem`
function can create a SQLite database in memory.
:py:func:`~simplesqlite.connect_sqlite_db_mem` function can create a SQLite database in memory.
This function will return |SimpleSQLite| instance,
the instance can execute methods as well as a |SimpleSQLite| instance opened with write mode.

.. code:: python
.. code-block:: python
:caption: Sample code that make a table in memory

table_name = "sample_table"
con = simplesqlite.connect_sqlite_db_mem()

>>> import simplesqlite
>>> con = simplesqlite.connect_sqlite_db_mem()
>>> con.database_path
':memory:'
# 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,
attribute_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
data_matrix=data_matrix)

# display values in the table -----
six.print_(con.get_attribute_name_list(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
six.print_(record)

# display data type for each column in the table -----
six.print_(json.dumps(con.get_attr_type(table_name), indent=4))


.. code-block:: none
:caption: Output

['attr_a', 'attr_b', 'attr_c', 'attr_d', 'attr_e']
(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')
{
"attr_b": " REAL",
"attr_c": " TEXT",
"attr_a": " INTEGER",
"attr_d": " REAL",
"attr_e": " TEXT"
}
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DataProperty>=0.7.0
DataProperty>=0.8.0
jsonschema
pathvalidate>=0.4.2
pathvalidate>=0.5.1
path.py
six
xlrd
30 changes: 30 additions & 0 deletions sample/create_table/sample_create_table_in_mem_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
# encoding: utf-8


import json
import simplesqlite
import six

table_name = "sample_table"
con = simplesqlite.connect_sqlite_db_mem()

# 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,
attribute_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
data_matrix=data_matrix)

# display values in the table -----
six.print_(con.get_attribute_name_list(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
six.print_(record)

# display data type for each column in the table -----
six.print_(json.dumps(con.get_attr_type(table_name), indent=4))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setuptools.setup(
name="SimpleSQLite",
version="0.4.2",
version="0.4.3",
url="https://github.com/thombashi/SimpleSQLite",
bugtrack_url="https://github.com/thombashi/SimpleSQLite/issues",

Expand Down
8 changes: 4 additions & 4 deletions simplesqlite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def insert_many(self, table_name, insert_record_list):
self.validate_access_permission(["w", "a"])
self.verify_table_existence(table_name)

if dataproperty.is_empty_list_or_tuple(insert_record_list):
if dataproperty.is_empty_sequence(insert_record_list):
return

record_list = RecordConvertor.to_record_list(
Expand Down Expand Up @@ -780,7 +780,7 @@ def has_attribute_list(self, table_name, attribute_name_list):
'not_existing' table not found in /tmp/sample.sqlite
"""

if dataproperty.is_empty_list_or_tuple(attribute_name_list):
if dataproperty.is_empty_sequence(attribute_name_list):
return False

not_exist_field_list = [
Expand Down Expand Up @@ -959,7 +959,7 @@ def create_index_list(self, table_name, attribute_name_list):

self.validate_access_permission(["w", "a"])

if dataproperty.is_empty_list_or_tuple(attribute_name_list):
if dataproperty.is_empty_sequence(attribute_name_list):
return

table_attr_set = set(self.get_attribute_name_list(table_name))
Expand Down Expand Up @@ -999,7 +999,7 @@ def create_table_with_data(

self.validate_access_permission(["w", "a"])

if dataproperty.is_empty_list_or_tuple(data_matrix):
if dataproperty.is_empty_sequence(data_matrix):
raise ValueError("input data is null: '%s (%s)'" % (
table_name, ", ".join(attribute_name_list)))

Expand Down
2 changes: 1 addition & 1 deletion simplesqlite/loader/csv/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CsvTableFormatter(TableFormatter):
def to_table_data(self):
self._validate_source_data()

if dataproperty.is_empty_list_or_tuple(self._loader.header_list):
if dataproperty.is_empty_sequence(self._loader.header_list):
header_list = self._source_data[0]

if any([
Expand Down
2 changes: 1 addition & 1 deletion simplesqlite/sqlquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def make_insert(cls, table, insert_tuple, is_insert_many=False):

table = cls.to_table_str(table)

if dataproperty.is_empty_list_or_tuple(insert_tuple):
if dataproperty.is_empty_sequence(insert_tuple):
raise ValueError("empty insert list/tuple")

if is_insert_many:
Expand Down
4 changes: 2 additions & 2 deletions test/test_simplesqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ class Test_SimpleSQLite_get_profile:

def test_normal(self, con):
profile_list = con.get_profile()
assert dataproperty.is_empty_list_or_tuple(profile_list)
assert dataproperty.is_empty_sequence(profile_list)

def test_normal_profile(self, con_profile):
profile_list = con_profile.get_profile()
assert dataproperty.is_not_empty_list_or_tuple(profile_list)
assert dataproperty.is_not_empty_sequence(profile_list)


class Test_SimpleSQLite_get_sqlite_master:
Expand Down