Baby Language Lab Scripts
A collection of data processing tools.
 All Classes Namespaces Files Functions Variables Pages
mem_database.py
Go to the documentation of this file.
1 ## @package db.mem_database
2 
3 from db.database import Database
4 
5 ## This class provides all the functionality of database.py, but using an in-memory database (non-persistent).
6 # An in-memory database is significantly faster than a disk-based one. This can be useful if you want
7 # simple SQL-query/sort functionality to sift through some data. You can build youself a temporary DB and
8 # even dump the results to a csv file when you're done. See CSVDatabase.py for more info on that sort of thing.
10  ## Constructor
11  # @param self
12  def __init__(self):
13  #create an in-memory SQLite database, just pass in this special identifier instead of a filename
14  super(MemDatabase, self).__init__(':memory:')
15 
16  ## Writes this in-memory database to a *.db file on disk
17  # @param self
18  # @param filename (string) path to the *.db file you wish to write to (will be created if it doesn't exist)
19  def dump_to_file(self, filename):
20  file_db = Database(filename)
21  sql_iter = self.conn.iterdump()
22 
23  for line in sql_iter:
24  file_db.execute_stmt(line)
25 
26  file_db.close()