MCPcopy
hub / github.com/coleifer/sqlite-web / initialize_dataset

Function initialize_dataset

sqlite_web/sqlite_web.py:1582–1615  ·  view source on GitHub ↗
(filename)

Source from the content-addressed store, hash-verified

1580 return redirect(url_for('login'))
1581
1582def initialize_dataset(filename):
1583 dataset_kw = {}
1584 if peewee_version >= (3, 14, 9):
1585 dataset_kw['include_views'] = True
1586
1587 if dataset_config['read_only']:
1588 if sys.version_info < (3, 4, 0):
1589 die('Python 3.4.0 or newer is required for read-only access.')
1590 if peewee_version < (3, 5, 1):
1591 die('Peewee 3.5.1 or newer is required for read-only access.')
1592 db = SqliteDatabase('file:%s?mode=ro' % filename, uri=True)
1593 try:
1594 db.connect()
1595 except OperationalError:
1596 die('Unable to open database file in read-only mode. Ensure that '
1597 'the database exists in order to use read-only mode.')
1598 db.close()
1599 else:
1600 db = SqliteDatabase(filename)
1601
1602 if dataset_config['foreign_keys']:
1603 db.pragma('foreign_keys', True, permanent=True)
1604
1605 if dataset_config['extensions']:
1606 # Load extensions before performing introspection.
1607 for ext in extensions:
1608 db.load_extension(ext)
1609
1610 if dataset_config['startup_hook']:
1611 startup_hook(db)
1612
1613 dataset = SqliteDataSet(db, bare_fields=True, **dataset_kw)
1614 dataset.close()
1615 return dataset
1616
1617def initialize_app(filenames, read_only=False, password=None, url_prefix=None,
1618 extensions=None, foreign_keys=None, startup_hook=None):

Callers 2

_add_datasetFunction · 0.85
initialize_appFunction · 0.85

Calls 2

dieFunction · 0.85
SqliteDataSetClass · 0.85

Tested by

no test coverage detected