def add_table(self, table): """Add the new table.""" Driver.add_table(self, table) name = table.name self.collections[name] = self.datas[name] self.inc_collections[name] = self.increments[name] self.line_ids[name] = {}
def __init__(self): Driver.__init__(self) self.db_name = "datas" self.inc_name = "increments" self.connection = None self.datas = None self.increments = None self.collections = {} self.inc_collections = {} self.object_ids = {}
def open(self, configuration): """Open the connection. The connection must be set up in the 'connection' instance attribute. While redefining this method, you MUST call the parent AFTER setting up the connection. """ Driver.open(self, configuration) self.check_existing_tables()
def add_table(self, table): """Add the new table if it doesn't exist.""" Driver.add_table(self, table) name = table.name filename = self.location + "/" + name + ".yml" self.files[name] = filename if os.path.exists(filename): with open(filename, "r") as file: return self.read_table(name, file) return []
def add_table(self, table): """Add the new table if it doesn't exist.""" name = table.name existing_tables = list(self.tables.keys()) Driver.add_table(self, table) self.tables[name] = table if name not in existing_tables: fields = table.fields sql_fields = [] for field_name, constraint in fields.items(): instruction = self.instruction_create_field(field_name, constraint) sql_fields.append(instruction) query = "CREATE TABLE {} ({})".format(name, ", ".join(sql_fields)) self.execute_query(query)
def open(self, configuration): """Open the connexion.""" Driver.open(self, configuration) self.db_name = configuration["datas"] self.inc_name = configuration["increments"] # Try to connect self.connection = pymongo.Connection() # Create the datas and increments collections self.datas = self.connection[self.db_name] self.increments = self.connection[self.inc_name] # Set the collections self.collections = {} self.inc_collections = {} # Keep the IDs in cache self.line_ids = {} self.id_lines = {}
def open(self, configuration): """Open the connexion.""" Driver.open(self, configuration) location = configuration["location"] location = location.replace("\\", "/") if location.startswith("~"): location = os.path.expanduser("~") + location[1:] if location.endswith("/"): location = location[:-1] if not os.path.exists(location): # Try to create it os.makedirs(location) if not os.access(location, os.R_OK): raise exceptions.DriverInitializationError( "cannot read in {}".format(location)) if not os.access(location, os.W_OK): raise exceptions.DriverInitializationError( "cannot write in {}".format(location)) self.location = location self.files = {}
def close(self): """Close the data connector (nothing to be done).""" Driver.close(self)
def __init__(self): Driver.__init__(self) self.location = None self.auto_increments = {} self.to_update = set()
def close(self): """Close the data connector (simply close the conection).""" Driver.close(self) self.connection.close()
def __init__(self): Driver.__init__(self) self.format = "?" self.tables = {} self.connection = None