<commit_before>import knex = require("knex");
import redux = require("redux");
import {ModelState} from "../";
import {DataAdapter} from "./";
import {createAddDataSourceAction, createUpdateDataCacheAction, createRemoveDataSourceAction} from "../actions";


const dummy = (true as boolean as false) || knex({}); // Makes the return type of the function available for reference without calling it
export class SqlDataSourceAdapter implements DataAdapter {
    private _conn: typeof dummy;
    private _uuid: number;
    constructor(private store: redux.Store<ModelState>, filename: string) {
        const action = createAddDataSourceAction("sqlite-file", {path: filename}, {});
        this._uuid = action.payload.uuid;
        const connection = knex({
            client: "sqlite3",
            connection: { filename },
            useNullAsDefault: true
        });
        this._conn = connection;
        store.dispatch(action);
        this.updateCache();
    }
    updateCache() {
        return this._conn.select("DaysToManufacture", "ListPrice").from("Product").then(data => {
            const action = createUpdateDataCacheAction(this._uuid, data);
            this.store.dispatch(action);<commit_msg>Added functions for describing database schema.<commit_after>import knex = require("knex");
import redux = require("redux");
import {ModelState} from "../";
import {DataAdapter} from "./";
import {createAddDataSourceAction, createUpdateDataCacheAction, createRemoveDataSourceAction} from "../actions";


const dummy = (true as boolean as false) || knex({}); // Makes the return type of the function available for reference without calling it
export class SqlDataSourceAdapter implements DataAdapter {
    private _conn: typeof dummy;
    private _uuid: number;
    constructor(private store: redux.Store<ModelState>, filename: string) {
        const action = createAddDataSourceAction("sqlite-file", {path: filename}, {});
        this._uuid = action.payload.uuid;
        const connection = knex({
            client: "sqlite3",
            connection: { filename },
            useNullAsDefault: true
        });
        this._conn = connection;
        store.dispatch(action);
        this.updateCache();
    };
    describeTables() {
         return this._conn
            .select("name")
            .from("sqlite_master")
            .where("type", "table")
            .returning("name")
            .then((results: [{name: string}]) => {
                return results.map(table => {
                    return table.name;
                });
            });
    }
    describeColumns(table: string) {
        this._conn
        .raw("Pragma table_info(" + table + ")")
        .then((data: {"name": string}[]) => {
            let columns = data.map(column => {
                return column.name;
            })
            .filter(name => {
                return name != "rowguid";
            });
            return columns;
        });
    }
    updateCache() {
        return this._conn.select("DaysToManufacture", "ListPrice").from("Product").then(data => {
            const action = createUpdateDataCacheAction(this._uuid, data);
            this.store.dispatch(action);
{'fraction_non_alphanumeric': 0.12648344784509682, 'fraction_numerical': 0.0006246096189881324, 'mean_word_length': 2.5314222712238146, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3597751', 'n_tokens_mistral': 808, 'n_tokens_neox': 796, 'n_words': 209}