71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import easymacro as app
|
|
from .peewee import (
|
|
__exception_wrapper__,
|
|
AutoField,
|
|
Database,
|
|
DateField,
|
|
Entity,
|
|
NodeList,
|
|
SQL,
|
|
)
|
|
|
|
|
|
class FirebirdAutoField(AutoField):
|
|
extra = 'GENERATED BY DEFAULT AS IDENTITY'
|
|
|
|
def ddl(self, ctx):
|
|
accum = [Entity(self.column_name)]
|
|
data_type = self.ddl_datatype(ctx)
|
|
if data_type:
|
|
accum.append(data_type)
|
|
if self.unindexed:
|
|
accum.append(SQL('UNINDEXED'))
|
|
if self.extra:
|
|
accum.append(SQL(self.extra))
|
|
if self.primary_key:
|
|
accum.append(SQL('PRIMARY KEY'))
|
|
if not self.null:
|
|
accum.append(SQL('NOT NULL'))
|
|
if self.sequence:
|
|
accum.append(SQL("DEFAULT NEXTVAL('%s')" % self.sequence))
|
|
if self.constraints:
|
|
accum.extend(self.constraints)
|
|
if self.collation:
|
|
accum.append(SQL('COLLATE %s' % self.collation))
|
|
return NodeList(accum)
|
|
|
|
|
|
class FirebirdDateField(DateField):
|
|
|
|
def db_value(self, value):
|
|
return app.date_to_struct(value)
|
|
|
|
def python_value(self, value):
|
|
return app._to_date(value)
|
|
|
|
|
|
class LOBaseDatabase(Database):
|
|
|
|
def __init__(self, database, **kwargs):
|
|
super().__init__(database, **kwargs)
|
|
self._db = None
|
|
|
|
def _connect(self):
|
|
self._db = app.get_db(self.database)
|
|
return self._db
|
|
|
|
def execute_sql(self, sql, params=None, commit=True):
|
|
with __exception_wrapper__:
|
|
cursor = self._db.execute(sql, params)
|
|
return cursor
|
|
|
|
def last_insert_id(self, cursor, query_type=None):
|
|
# ~ app.mri(cursor)
|
|
return 1
|
|
|
|
# ~ def get_tables(self):
|
|
# ~ res = self.execute('SHOW TABLES;')
|
|
# ~ return [r[0] for r in res.fetchall()]
|