# Path: pyelt/datalayers/database.py
# class Column():
#     def __init__(self, name: str, type: str = 'text', tbl: 'Table' = None, default_value = '', pk = False, unique = False, indexed = False, nullable = True, fhir_name = '') -> None:
#         name = name.strip()
#         self.name = name.strip().lower()
#         if not isinstance(type, str):
#             if type == 23:
#                 type = 'integer'
#             else:
#                 type = 'text'
#         self.type = type.strip()
#         #todo length
#         self.length = ''
#         self.table = tbl
#         self.is_key = pk
#         self.is_unique = unique
#         self.is_indexed = indexed
#         self.nullable = nullable
#         self.default_value = default_value
#         self.fhir_name = fhir_name
# 
#     def __str__(self) -> str:
#         return self.name.lower()
# 
#     def __repr__(self) -> str:
#         return "{} ({})".format(self.name.lower(), self.type.lower())
# 
#     @staticmethod
#     def clear_name(name: str) -> str:
#         name = name.replace('(', '').replace(')', '')
#         name = name.replace('?', '')
#         name = name.replace('-', '')
#         name = name.replace(',', '')
#         name = name.replace('.', '')
#         name = name.replace(':', '')
#         name = name.replace('"', '')
#         name = name.replace(' ', '_')
#         name = name.replace('/', '_')
#         name = name.lower()
#         return name
# 
#     def get_table(self):
#         return self.table
# 
#     def __eq__(self, other):
#         # zet om in sql
#         return Condition(self.name, '=', other, table=self.table)
# 
#     def __ne__(self, other):
#         # zet om in sql
#         return Condition(self.name, '!=', other, table=self.table)
#         # return Condition('({} != {})'.format(self.name,other))
# 
#     def __gt__(self, other):
#         # zet om in sql
#         return Condition(self.name, '>', other, table=self.table)
#         # return Condition('({} > {})'.format(self.name,other))
# 
#     def __ge__(self, other):
#         # zet om in sql
#         return Condition(self.name, '>=', other, table=self.table)
#         # return Condition('({} >= {})'.format(self.name,other))
# 
#     def __lt__(self, other):
#         # zet om in sql
#         return Condition(self.name, '<', other, table=self.table)
#         # return Condition('({} < {})'.format(self.name,other))
# 
#     def __le__(self, other):
#         # zet om in sql
#         return Condition(self.name, '<=', other, table=self.table)
#         # return Condition('({} <= {})'.format(self.name,other))
# 
#     def is_in(self, item):
#         return Condition(self.name, 'in', item, table=self.table)
# 
#     def between(self, item1, item2):
#         item = '{} AND {}'.format(item1, item2)
#         return Condition(self.name, 'between', item, table=self.table)
# 
#     def join(self, item):
#         sql = self.name + '||' + item.name
#         if isinstance(item, (list, tuple)):
#             sql = self.name + '||' + '||'.join(item)
#         return SqlSnippet(sql, table=self.table)


import csv
from pyelt.datalayers.database import Column
            self.reflect()
        return self.columns

class CsvFile(File):
    def __init__(self, file_name, **kwargs):
        super().__init__(file_name )
        self.quote = '"'
        self.delimiter = ';'
        self.file_kwargs = {}
        self.csv_kwargs = {}
        self.csv_kwargs['delimiter'] = self.delimiter
        for k,v in kwargs.items():
            if k == 'encoding':
                self.file_kwargs[k] = v
                if v == 'utf-8-sig':
                    v = 'utf8'
                self.encoding = v
            elif k == 'delimiter':
                self.csv_kwargs[k] = v
                self.delimiter = v
            elif k == 'quote':
                self.quote = v
        self.kwargs = kwargs

    def reflect(self):
        # lees eerste regel
        with open(self.file_name, 'r', **self.file_kwargs) as csvfile:
            reader = csv.reader(csvfile, **self.csv_kwargs)
            column_names = next(reader, None)
            for name in column_names:

# Path: pyelt/datalayers/database.py
# class Column():
#     def __init__(self, name: str, type: str = 'text', tbl: 'Table' = None, default_value = '', pk = False, unique = False, indexed = False, nullable = True, fhir_name = '') -> None:
#         name = name.strip()
#         self.name = name.strip().lower()
#         if not isinstance(type, str):
#             if type == 23:
#                 type = 'integer'
#             else:
#                 type = 'text'
#         self.type = type.strip()
#         #todo length
#         self.length = ''
#         self.table = tbl
#         self.is_key = pk
#         self.is_unique = unique
#         self.is_indexed = indexed
#         self.nullable = nullable
#         self.default_value = default_value
#         self.fhir_name = fhir_name
# 
#     def __str__(self) -> str:
#         return self.name.lower()
# 
#     def __repr__(self) -> str:
#         return "{} ({})".format(self.name.lower(), self.type.lower())
# 
#     @staticmethod
#     def clear_name(name: str) -> str:
#         name = name.replace('(', '').replace(')', '')
#         name = name.replace('?', '')
#         name = name.replace('-', '')
#         name = name.replace(',', '')
#         name = name.replace('.', '')
#         name = name.replace(':', '')
#         name = name.replace('"', '')
#         name = name.replace(' ', '_')
#         name = name.replace('/', '_')
#         name = name.lower()
#         return name
# 
#     def get_table(self):
#         return self.table
# 
#     def __eq__(self, other):
#         # zet om in sql
#         return Condition(self.name, '=', other, table=self.table)
# 
#     def __ne__(self, other):
#         # zet om in sql
#         return Condition(self.name, '!=', other, table=self.table)
#         # return Condition('({} != {})'.format(self.name,other))
# 
#     def __gt__(self, other):
#         # zet om in sql
#         return Condition(self.name, '>', other, table=self.table)
#         # return Condition('({} > {})'.format(self.name,other))
# 
#     def __ge__(self, other):
#         # zet om in sql
#         return Condition(self.name, '>=', other, table=self.table)
#         # return Condition('({} >= {})'.format(self.name,other))
# 
#     def __lt__(self, other):
#         # zet om in sql
#         return Condition(self.name, '<', other, table=self.table)
#         # return Condition('({} < {})'.format(self.name,other))
# 
#     def __le__(self, other):
#         # zet om in sql
#         return Condition(self.name, '<=', other, table=self.table)
#         # return Condition('({} <= {})'.format(self.name,other))
# 
#     def is_in(self, item):
#         return Condition(self.name, 'in', item, table=self.table)
# 
#     def between(self, item1, item2):
#         item = '{} AND {}'.format(item1, item2)
#         return Condition(self.name, 'between', item, table=self.table)
# 
#     def join(self, item):
#         sql = self.name + '||' + item.name
#         if isinstance(item, (list, tuple)):
#             sql = self.name + '||' + '||'.join(item)
#         return SqlSnippet(sql, table=self.table)


# Path: pyelt/sources/files.py
import csv
from pyelt.datalayers.database import Column

            self.reflect()
        return self.columns

class CsvFile(File):
    def __init__(self, file_name, **kwargs):
        super().__init__(file_name )
        self.quote = '"'
        self.delimiter = ';'
        self.file_kwargs = {}
        self.csv_kwargs = {}
        self.csv_kwargs['delimiter'] = self.delimiter
        for k,v in kwargs.items():
            if k == 'encoding':
                self.file_kwargs[k] = v
                if v == 'utf-8-sig':
                    v = 'utf8'
                self.encoding = v
            elif k == 'delimiter':
                self.csv_kwargs[k] = v
                self.delimiter = v
            elif k == 'quote':
                self.quote = v
        self.kwargs = kwargs

    def reflect(self):
        # lees eerste regel
        with open(self.file_name, 'r', **self.file_kwargs) as csvfile:
            reader = csv.reader(csvfile, **self.csv_kwargs)
            column_names = next(reader, None)
            for name in column_names:

                name = Column.clear_name(name)