breezedb Package

db Module

db.create_db(path, name)

Create a database file in the specified path.

Parameters:
  • path (str) – path where the database should be created
  • name (str) – name for the database
Raises:
  • IOError – cannot write to path
  • OSError – error writing to database
  • Exception – database already exists
db.get_table_list(db_path)

Get a list of tables present in the database.

Parameters:

db_path (str) – path to the database

Returns:

list of all the tables ordered by key

Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – not a breezedb database
db.is_brdb(db_path)

Determine whether the specified file is a breezedb database or not.

Parameters:db_path (str) – path to the database
Returns:True or False
db.remove_db(db_path)

Remove the breezedb database in the specified path.

Parameters:

db_path (str) – path to the database

Raises:
  • IOError – cannot open file
  • OSError – cannot delete file
  • Exception – not a breezedb database

element Module

element.create_row(element_list, table_name, db_path)

Creates a row of elements in the given table.

Loops through the list of fields in the table and adds the corresponding element.

Parameters:
  • element_list – list of elements to add to the table. Elements must appear in the order the fields are listed in the table, and there must be one element per field in the list, even if they are left blank
  • table_name (str) – name of the table that will contain the row
  • db_path (str) – path to the database
Rasies IndexError:
 

invalid number of elements

Raises:
  • IOError – cannot open file
  • KeyError – invalid key
  • OSError – error writing to database
  • TypeError – data type error
  • Exception – table does not exist
element.empty_element(index, field_name, table_name, db_path)

Empty the content of a specific element.

The content is emptied instead of removing the whole element because a single element cannot be removed.

Parameters:
  • index (int) – index of the element to empty
  • field_name (str) – name of the field that contains the element
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid key
  • OSError – error writing to database
  • TypeError – invalid index type
  • Exception – row does not exist
element.exists_row(index, table_name, db_path)

Check if a row with the given index exists in the table.

Parameters:
  • index (int) – index of check
  • table_name (str) – name of the table
  • db_path (str) – path to the database
Returns:

True or false

Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid key
  • TypeError – invalid index type
  • Exception – table does not exist
element.get_element_data(index, field_name, table_name, db_path)

Get the data contained in a specific element.

Parameters:
  • element_index (int) – index of the row
  • field_name (str) – name of the field that contains the element
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Returns:

content of the element

Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid key
  • TypeError – invalid index type
  • Exception – row does not exist
element.modify_element(index, field_name, table_name, db_path, new_content)

Modify the content of an element.

Parameters:
  • index (int) – index of the element to modify
  • field_name (str) – name of the field that contains the element
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
  • new_content (str) – new content to store in the element
Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid key
  • OSError – error writing to database
  • TypeError – invalid index type
  • Exception – row does not exist
element.remove_row(index, table_name, db_path)

Remove an element row from the specified table.

Parameters:
  • element_index (int) – index of the element row to remove
  • table_name (str) – name of the table that contains the field
  • database (str) – path to the database
Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid key
  • OSError – error writing to database
  • TypeError – invalid index type
  • Exception – row does not exist

field Module

field.create_field(field_name, field_type, table_name, db_path)

Create a new field in the table.

Adds the empty field to already existing rows.

Parameters:
  • field_name (str) – name for the new field
  • field_type (str) – data type, available types are ‘str’, ‘int’, ‘float’, ‘bool’
  • table_name (str) – name of the table that will contain the field
  • db_path (str) – path to the database
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – field already exists, not a valid data type
field.empty_field_row(index, field_name, table_name, db_path)

Empty the contents of a field on a single row of the table.

Parameters:
  • index (int) – index of the desired row
  • field_name (str) – name of the field to empty
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – field does not exist
field.empty_field_table(field_name, table_name, db_path)

Empty the contents of a field on every row of the table.

Parameters:
  • field_name (str) – name of the field to empty
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – field does not exist
field.exists_field(field_name, table_name, db_path)

Check whether a field exists in the table or not.

Parameters:
  • field_name (str) – name of the field to check
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Returns:

True or False

Raises IOError:

cannot open file

field.get_field_data(field_name, table_name, db_path)

Get the data contained in the field for every row in the table.

Parameters:
  • field_name (str) – name of the field to get the elements from
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Returns:

data list sorted by order of appearance

Raises:
  • IOError – cannot open file
  • KeyError – invalid field key
  • Exception – field does not exist
field.get_field_type(field_name, table_name, db_path)

Get the data type contained in a specific field for parsing purposes.

Parameters:
  • field_name (str) – name of the field to get the elements from
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
Returns:

string with the data type

Raises:
  • IOError – cannot open file
  • KeyError – invalid field key
  • Exception – field does not exist
field.remove_field(field_name, table_name, db_path)

Remove a field from the table.

Removes the field from both the list of fields and every row of the table.

Parameters:
  • field_name (str) – name of the field to remove
  • table_name (str) – name of the table that contains the field
  • database (str) – path to the database
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – field does not exist
field.rename_field(field_name, table_name, db_path, new_name)

Rename a field.

Renames both the element in the fields list and every row of the table.

Parameters:
  • field_name (str) – current name of the field
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
  • new_name (str) – new name for the field
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – field does not exist, new field already exists
field.swap_fields(index1, index2, table_name, db_path)

Swap two field indexes in the specified table. This affects the priority order of the fields.

Parameters:
  • index1 (int) – first field index to swap
  • index2 (int) – second field index to swap
  • table_name (str) – table in which to perform the swap
  • db_path (str) – path to the database
Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • OSError – error writing to database
  • TypeError – invalid index type
  • Exception – field does not exist

table Module

table.create_table(table_name, db_path)

Create a new table in the database.

Parameters:
  • table_name (str) – name of the new table
  • db_path (str) – path to the database
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – table already exists
table.exists_table(table_name, db_path)

Check whether a table exists in the database or not.

Parameters:
  • table_name (str) – name of the table to find
  • db_path (str) – path to the database
Returns:

True or False

Raises:
  • IOError – cannot open file
  • Exception – not a breezedb database
table.get_field_list(table_name, db_path)

Get a list of fields present in the table.

Parameters:
  • table_name (str) – name of the table
  • db_path (str) – path to the database
Returns:

list containing the fields of the table

Raises:
  • IOError – cannot open file
  • KeyError – invalid key
  • Exception – table does not exist
table.get_row(index, table_name, db_path)

Get the elements located in a row of the table.

Parameters:
  • index (int) – index of the row
  • table_name (str) – name of the table
  • db_path (str) – path to the database
Returns:

list containing the data of the row, ordered by field

Raises:
  • IndexError – invalid index
  • IOError – cannot open file
  • KeyError – invalid field key
  • Exception – table does not exist
table.get_row_list(table_name, db_path)

Get a list of all the rows in the table

Parameters:
  • table_name (str) – name of the table
  • db_path (str) – path to the database
Returns:

list of data rows in dictionary format

Raises:
  • IOError – cannot open file
  • KeyError – invalid field key
  • Exception – table does not exist
table.remove_table(table_name, db_path)

Remove a table from the database.

Parameters:
  • table_name (str) – name of the table to remove
  • db_path (str) – path to the database
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – not a breezedb database, table does not exist
table.rename_table(table_name, db_path, new_name)

Rename a table from the database.

Parameters:
  • table_name (str) – current name of the table
  • db_path (str) – path to the database
  • new_name (str) – new name for the table
Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – table does not exist, new table already exists
table.search_data(data, table_name, db_path, field_name=None, ignore_case=True)

Search data in the table and obtain the index of the rows that match the criteria.

Parameters:
  • data (str) – data to find
  • table_name (str) – name of the table that contains the field
  • db_path (str) – path to the database
  • field_name (str) – name of the field that contains the element. If None is specified, then the function will search in all the fields of the table in every row
  • ignore_case (Boolean) – whether or not to ignore the case when searching
Returns:

list of indexes that match the criteria

Raises:
  • IOError – cannot open file
  • OSError – error writing to database
  • Exception – not a breezedb database, table does not exist

query Module

class query.Parser(query)

Parses the query and divides it into subqueries where possible.

Parameters:query (str) – query to parse
create()

Run a CREATE operation. This operation works with databases, tables and fields.

Raises Exception:
 incorrect query syntax, incorrect number of parameters
empty()

Run an EMPTY operation. This operation works with fields and elements.

Raises Exception:
 incorrect query syntax
exists()

Run an EXISTS operation. This operation works with tables, fields and rows.

Returns:True or False
Raises Exception:
 incorrect query syntax
get()

Run a GET operation. This operation works with databases, tables, fields and elements.

Returns:list of results obtained from the query
Raises Exception:
 incorrect query syntax
modify()

Run a MODIFY operation. This operation only works with elements.

Raises Exception:
 incorrect query syntax
remove()

Run a REMOVE operation. This operation works with databases, tables, fields and elements.

Raises Exception:
 incorrect query syntax
rename()

Run a RENAME operation. This operation works with tables and fields.

Raises Exception:
 incorrect query syntax
run()

Run the query.

search()

Run a SEARCH operation.

Returns:list of results obtained from the query
Raises Exception:
 incorrect query syntax
swap()

Run a SWAP operation. This operation only works with fields.

Raises Exception:
 incorrect query syntax
query.run_query(query)

Parse and execute a query in the database.

This function divides the query (if there are more than one) by using the string ‘>>’ and then runs a parser for each one.

Parameters:query (str) – query to execute

Table Of Contents

Previous topic

breezedb

This Page