File: sqlite_helpers.py

package info (click to toggle)
peewee 3.14.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,184 kB
  • sloc: python: 33,050; makefile: 126; ansic: 109; sh: 10
file content (28 lines) | stat: -rw-r--r-- 809 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from peewee import sqlite3


def json_installed():
    if sqlite3.sqlite_version_info < (3, 9, 0):
        return False
    # Test in-memory DB to determine if the FTS5 extension is installed.
    tmp_db = sqlite3.connect(':memory:')
    try:
        tmp_db.execute('select json(?)', (1337,))
    except:
        return False
    finally:
        tmp_db.close()
    return True


def json_patch_installed():
    return sqlite3.sqlite_version_info >= (3, 18, 0)


def compile_option(p):
    if not hasattr(compile_option, '_pragma_cache'):
        conn = sqlite3.connect(':memory:')
        curs = conn.execute('pragma compile_options')
        opts = [opt.lower().split('=')[0].strip() for opt, in curs.fetchall()]
        compile_option._pragma_cache = set(opts)
    return p in compile_option._pragma_cache