https://github.com/moriyoshi/tableau
Tableau is a collection of helper classes for building test fixtures and seed data
https://github.com/moriyoshi/tableau
Last synced: 6 months ago
JSON representation
Tableau is a collection of helper classes for building test fixtures and seed data
- Host: GitHub
- URL: https://github.com/moriyoshi/tableau
- Owner: moriyoshi
- Created: 2012-07-06T08:55:59.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-07-20T20:00:28.000Z (almost 13 years ago)
- Last Synced: 2024-11-13T06:13:13.344Z (6 months ago)
- Language: Python
- Size: 204 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
Awesome Lists containing this project
README
Tableau
=======Tableau is a collection of helper classes for building test fixtures and seed data.
- Model composition without any predefined schemas. The model object relationships are automatically deduced through the value annotations::
from tableau import Datum
foo = Datum(
'Foo', ('id'), # schema name / identifiers
id=1,
field_a=1,
field_b=2,
collection=one_to_many([
Datum(
'Bar', auto('id'), # id will be automagically generated by the walker
field_c=1
),
Datum(
'Bar', auto('id'),
field_c=1
),
],
referring_fields='foo_id'
)
)- Export the model object graph to plain ANSI SQL statements, in the ORM-agnostic manner::
import sys
from tableau import Datum, DataSuite, DataWalker
from tableau.sql import SQLGenerator# ...
suite = DataSuite()
DataWalker(suite)(foo)
SQLGenerator(sys.stdout, encoding='utf-8')(suite)The above yields the following SQL statements::
INSERT INTO `Foo` (`id`, `field_a`, `field_b`) VALUES
(1, 1, 2);
INSERT INTO `Bar` (`id`, `field_c`, `foo_id`) VALUES
(1, 1, 1),
(2, 1, 1);- Automatically mapping the existing SQLAlchemy tables / mapped classes
to the `Data`::from tableau.sqla import newSADatum
# metadata = ...
# Base = ...
# session = ...class Foo(Base):
__tablename__ = 'foos'
id = Column(Integer, primary_key=True)
field = Column(String)def some_model_specific_method(self):
return self.fieldDatum = newSADatum(metadata)
datum = Datum(
'foos', ('id'),
field='test'
)
print datum.some_model_specific_method() # 'test'
session.add(datum) # it can even be added to the session!