mirror of
https://gitlab.com/datalifeit/trytond-edw_mssql
synced 2023-12-14 05:52:58 +01:00
Simplify field mapping code.
This commit is contained in:
parent
44f36eed79
commit
93985a63e4
27
connector.py
27
connector.py
|
@ -1,25 +1,26 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.modules.edw.instance import BackendConnector
|
||||
import pymssql
|
||||
|
||||
INSERT_QUERY = (
|
||||
"""INSERT INTO "%(tablename)s" """ +
|
||||
"""(%(fields)s) """ +
|
||||
"""VALUES (%(values)s)""")
|
||||
"""VALUES (%(values)s);""")
|
||||
|
||||
TRUNCATE_QUERY = (
|
||||
"""TRUNCATE TABLE "%(tablename)s" """)
|
||||
"""TRUNCATE TABLE "%(tablename)s"; """)
|
||||
|
||||
CREATE_QUERY = (
|
||||
"""IF NOT EXISTS (select * from sysobjects """ +
|
||||
""" where name='%(tablename)s' and xtype='U') """ +
|
||||
""" CREATE TABLE "%(tablename)s" (%(fields)s)""")
|
||||
""" CREATE TABLE "%(tablename)s" (%(fields)s);""")
|
||||
|
||||
DELETE_QUERY = (
|
||||
"""IF EXISTS (select * from sysobjects """ +
|
||||
""" where name='%(tablename)s' and xtype='U') """ +
|
||||
""" DROP TABLE "%(tablename)s" """)
|
||||
""" DROP TABLE "%(tablename)s"; """)
|
||||
|
||||
|
||||
class BackendConnectorMSsql(BackendConnector):
|
||||
|
@ -74,13 +75,17 @@ class BackendConnectorMSsql(BackendConnector):
|
|||
|
||||
def get_mapped_types(self):
|
||||
return {
|
||||
'integer': 'int',
|
||||
'char': 'nvarchar(max)',
|
||||
'date': 'date',
|
||||
'numeric': 'numeric',
|
||||
'timedelta': 'nvarchar(32)',
|
||||
'timestamp': 'datetime',
|
||||
'float': 'numeric(18,0)'
|
||||
fields.Integer: 'int',
|
||||
fields.Many2One: 'int',
|
||||
fields.Char: 'nvarchar(max)',
|
||||
fields.Text: 'nvarchar(max)',
|
||||
fields.Selection: 'nvarchar(max)',
|
||||
fields.Date: 'date',
|
||||
fields.Numeric: 'numeric(32, 18)',
|
||||
fields.TimeDelta: 'nvarchar(32)',
|
||||
fields.Timestamp: 'datetime',
|
||||
fields.Float: 'numeric(32, 18)',
|
||||
fields.Reference: 'nvarchar(max)'
|
||||
}
|
||||
|
||||
def execute_query(self, query, results=None):
|
||||
|
|
Loading…
Reference in a new issue