Ejemplo n.º 1
0
       },
   },
}

# ローカル環境で利用するDB設定
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite_demo'),
    }
}

# SQLAlchemyで利用するDB設定
ALDJEMY_ENGINES = {
    'sqlite3': 'sqlite+pysqlite'
}

# DjangoModelのFieldTypeからSQLAlchemyのFieldTypeへ変換定義を一部上書きする設定
# SQLiteにはDate,DateTime型が存在しないため、ORM側でconvert処理を実装します
# (String <--> python's datetime)
# なお、DjangoORM側でDateField型を選択している場合は正常に動作するため、
# ここでの指定は本来DateTimeField型のみでも問題ありません
# おそらくSQLAlchemy側のバグ? 仕様?
# (Python3 SQLAlchemy DateTime型をSQLiteで利用すると値がbytesになる)
ALDJEMY_DATA_TYPES = {
    'DateTimeField': simple(SQLiteDateTime)
}



Ejemplo n.º 2
0
    return wrapper


########NEW FILE########
__FILENAME__ = table
#! /usr/bin/env python

from sqlalchemy import types, Column, Table
from django.db.models.loading import AppCache
from aldjemy.types import simple, foreign_key, varchar
from django.conf import settings

DATA_TYPES = {
    'AutoField':
    simple(types.Integer),
    'BooleanField':
    simple(types.Boolean),
    'CharField':
    varchar,
    'CommaSeparatedIntegerField':
    varchar,
    'DateField':
    simple(types.Date),
    'DateTimeField':
    simple(types.DateTime),
    'DecimalField':
    lambda x: types.Numeric(scale=x.decimal_places, precision=x.max_digits),
    'FileField':
    varchar,
    'FilePathField':
Ejemplo n.º 3
0
#! /usr/bin/env python

from sqlalchemy import types, Column, Table
from django.db.models.loading import AppCache
from aldjemy.types import simple, foreign_key, varchar
from django.conf import settings


DATA_TYPES = {
    'AutoField':         simple(types.Integer),
    'BooleanField':      simple(types.Boolean),
    'CharField':         varchar,
    'CommaSeparatedIntegerField': varchar,
    'DateField':         simple(types.Date),
    'DateTimeField':     simple(types.DateTime),
    'DecimalField':      lambda x: types.Numeric(scale=x.decimal_places,
                                                 precision=x.max_digits),
    'FileField':         varchar,
    'FilePathField':     varchar,
    'FloatField':        simple(types.Float),
    'IntegerField':      simple(types.Integer),
    'BigIntegerField':   simple(types.BigInteger),
    'IPAddressField':    lambda field: types.CHAR(length=15),
    'NullBooleanField':  simple(types.Boolean),
    'OneToOneField':     foreign_key,
    'ForeignKey':        foreign_key,
    'PositiveIntegerField': simple(types.Integer),
    'PositiveSmallIntegerField': simple(types.SmallInteger),
    'SlugField':         varchar,
    'SmallIntegerField': simple(types.SmallInteger),
    'TextField':         simple(types.Text),
Ejemplo n.º 4
0
#! /usr/bin/env python

import sqlalchemy.dialects.postgresql
from django.apps import apps as django_apps
from django.conf import settings
from sqlalchemy import Column, Table, types

from aldjemy import postgres
from aldjemy.types import foreign_key, simple, varchar

DATA_TYPES = {
    "AutoField":
    simple(types.Integer),
    "BigAutoField":
    simple(types.BigInteger),
    "BooleanField":
    simple(types.Boolean),
    "CharField":
    varchar,
    "CommaSeparatedIntegerField":
    varchar,
    "DateField":
    simple(types.Date),
    "DateTimeField":
    simple(types.DateTime),
    "DecimalField":
    lambda x: types.Numeric(scale=x.decimal_places, precision=x.max_digits),
    "DurationField":
    simple(types.Interval),
    "FileField":
    varchar,
Ejemplo n.º 5
0
#! /usr/bin/env python

import sqlalchemy.dialects.postgresql
from django.apps import apps as django_apps
from django.conf import settings
from sqlalchemy import Column, Table, types

from aldjemy import postgres
from aldjemy.types import foreign_key, simple, varchar

DATA_TYPES = {
    "AutoField": simple(types.Integer),
    "BigAutoField": simple(types.BigInteger),
    "BooleanField": simple(types.Boolean),
    "CharField": varchar,
    "CommaSeparatedIntegerField": varchar,
    "DateField": simple(types.Date),
    "DateTimeField": simple(types.DateTime),
    "DecimalField": lambda x: types.Numeric(
        scale=x.decimal_places, precision=x.max_digits
    ),
    "DurationField": simple(types.Interval),
    "FileField": varchar,
    "FilePathField": varchar,
    "FloatField": simple(types.Float),
    "IntegerField": simple(types.Integer),
    "BigIntegerField": simple(types.BigInteger),
    "IPAddressField": lambda field: types.CHAR(length=15),
    "NullBooleanField": simple(types.Boolean),
    "OneToOneField": foreign_key,
    "ForeignKey": foreign_key,
Ejemplo n.º 6
0
#! /usr/bin/env python

from sqlalchemy import types, Column, Table

from django.conf import settings
try:
    from django.apps import apps as django_apps
except ImportError:
    from django.db.models.loading import AppCache
    django_apps = AppCache()

from aldjemy.types import simple, foreign_key, varchar


DATA_TYPES = {
    'AutoField':         simple(types.Integer),
    'BooleanField':      simple(types.Boolean),
    'CharField':         varchar,
    'CommaSeparatedIntegerField': varchar,
    'DateField':         simple(types.Date),
    'DateTimeField':     simple(types.DateTime),
    'DecimalField':      lambda x: types.Numeric(scale=x.decimal_places,
                                                 precision=x.max_digits),
    'FileField':         varchar,
    'FilePathField':     varchar,
    'FloatField':        simple(types.Float),
    'IntegerField':      simple(types.Integer),
    'BigIntegerField':   simple(types.BigInteger),
    'IPAddressField':    lambda field: types.CHAR(length=15),
    'NullBooleanField':  simple(types.Boolean),
    'OneToOneField':     foreign_key,
Ejemplo n.º 7
0
        'django.db.backends': {
            'level': 'WARN',
            'handers': ['console'],
        },
        'sqlalchemy.engine': {
            'level': 'INFO',
            'handers': ['console'],
        },
    },
}

# ローカル環境で利用するDB設定
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite_demo'),
    }
}

# SQLAlchemyで利用するDB設定
ALDJEMY_ENGINES = {'sqlite3': 'sqlite+pysqlite'}

# DjangoModelのFieldTypeからSQLAlchemyのFieldTypeへ変換定義を一部上書きする設定
# SQLiteにはDate,DateTime型が存在しないため、ORM側でconvert処理を実装します
# (String <--> python's datetime)
# なお、DjangoORM側でDateField型を選択している場合は正常に動作するため、
# ここでの指定は本来DateTimeField型のみでも問題ありません
# おそらくSQLAlchemy側のバグ? 仕様?
# (Python3 SQLAlchemy DateTime型をSQLiteで利用すると値がbytesになる)
ALDJEMY_DATA_TYPES = {'DateTimeField': simple(SQLiteDateTime)}
Ejemplo n.º 8
0
"""Unitテスト向けのsettingsモジュールです
"""

from curama.settings.common import *
from aldjemy.types import simple
from curama.lib.aldjemy.custom_types import SQLiteDate, SQLiteDateTime

# デバッグ設定
DEBUG = False

# Database
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}

# SQLAlchemyで利用するDB設定
ALDJEMY_ENGINES = {"sqlite3": "sqlite+pysqlite"}

# DjangoModelのFieldTypeからSQLAlchemyのFieldTypeへ変換定義を一部上書きする設定
# SQLiteにはDate,DateTime型が存在しないため、ORM側でconvert処理を実装します
# (String <--> python's datetime)
# なお、DjangoORM側でDateField型を選択している場合は正常に動作するため、
# ここでの指定は本来DateTimeField型のみでも問題ありません
# おそらくSQLAlchemy側のバグ? 仕様?
# (Python3 SQLAlchemy DateTime型をSQLiteで利用すると値がbytesになる)
ALDJEMY_DATA_TYPES = {"DateTimeField": simple(SQLiteDateTime)}
Ejemplo n.º 9
0
import django
from django.conf import settings

try:
    from django.apps import apps as django_apps
except ImportError:
    from django.db.models.loading import AppCache

    django_apps = AppCache()

from aldjemy.types import simple, foreign_key, varchar


DATA_TYPES = {
    "AutoField": simple(types.Integer),
    "BigAutoField": simple(types.BigInteger),
    "BooleanField": simple(types.Boolean),
    "CharField": varchar,
    "CommaSeparatedIntegerField": varchar,
    "DateField": simple(types.Date),
    "DateTimeField": simple(types.DateTime),
    "DecimalField": lambda x: types.Numeric(scale=x.decimal_places, precision=x.max_digits),
    "DurationField": simple(types.Interval),
    "FileField": varchar,
    "FilePathField": varchar,
    "FloatField": simple(types.Float),
    "IntegerField": simple(types.Integer),
    "BigIntegerField": simple(types.BigInteger),
    "IPAddressField": lambda field: types.CHAR(length=15),
    "NullBooleanField": simple(types.Boolean),
Ejemplo n.º 10
0

class IntegerDateTime(TypeDecorator):
    impl = Integer

    def process_bind_param(self, value, _):
        if value is None:
            return None
        elif isinstance(value, datetime.datetime):
            return int(value.strftime('%s'))
        raise ValueError("Can operate only on datetime values. "
                         "Offending value type: {0}".format(type(value).__name__))

    def process_result_value(self, value, _):
        if value is not None:
            return datetime.datetime.fromtimestamp(float(value))


DATA_TYPES[models.IntegerDateTimeField().get_internal_type()] = simple(IntegerDateTime)

prepare_models()

Fund = models.Fund.sa
FxRate = models.FxRate.sa
Nav = models.Nav.sa
Order = models.Order.sa
Symbol = models.Symbol.sa
Trade = models.Trade.sa

pandas_sql_query = lambda q, *a, **k: pandas.read_sql(q.statement, q.session.bind, *a, **k)