db_commands module

Includes a variety of commands to make querying the SQLite database simple, encapsulated in a class called Query.

When run directly it builds the necessary tables to run the Citation Graph program, for if and when the database is deleted.

class db_commands.Query(db_filename)

Bases: object

close()

Commits changes and closes connection to database.

create_table(table, columns)

Creates a table.

Parameters:
  • table (string) –
  • columns (tuple of strings) –
  • c – database connection.
drop_table(table)

Drops table.

Parameters:
  • table (string) –
  • c – database connection.
follow_edges(text_key, direction='cited', full_node_list=[], full_edge_list=[], iteration=1)

Helper function to get outgoing edges from text and connected nodes.

full(table)

Shows full table.

Parameters:table (string) –
get_creator_surnames(text_key)

Returns author(s) for given text key.

Parameters:text_key (string) –
json_graph(text_key, radius=1)

Returns nodes and edges for JSON citation graph centred on specified text.

text_key (string): in BetterBibTex format [authForeIni][authEtAl][year]. radius (int): TODO degrees of separation between focal text and others included.

open()

Opens connection to database.

reboot()

Create necessary tables for Literature classes.

remove_duplicate_rows(table, repeated_value, all_but=1, column='key')

Removes rows with specified duplicate value.

Parameters:
  • table (string) –
  • repeated_value
  • c – database connection
  • column (string) – default is ‘key’ which will only remove duplicate rows, but any column could be specified to remove all rows with duplicate values.
remove_row(table, rowid)

Removes specified row from table.

Parameters:
  • table (string) –
  • rowid (int) –
  • c – database connection
save_row_to_table(table, row, allow_duplicate=False)

Saves row of data to table.

Parameters:data (list) –
search(table, column, value, with_rowid=False)

Searches column in table for specified value.

Parameters:
  • table (string) –
  • column (string) –
  • value
  • c – database connection
  • with_rowid (Boolean) –
test()

Shows that tests are successfully importing db_commands