How to use the alasql.compile function in alasql

To help you get started, we’ve selected a few alasql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thiagodp / concordialang / modules / db / AlaSqlTableCreator.ts View on Github external
const sqlColumns = this._sqlHelper.generateSqlColumns( columnRow.cells, sqlTypes );
        const createCommand = this._sqlHelper.generateCreateWithTypes( table.internalName, sqlColumns );
        try {
            // console.log( 'TABLE CREATION COMMAND: ', createCommand );
            dbConnection.exec( createCommand ); // Creates the table if it does not exist
        } catch ( e ) {
            const msg = `Error creating the table "${table.name}": ${e.message}`;
            throw new RuntimeException( msg, table.location );
        }

        // Prepares a parameterized insert

        const insertCommand = this._sqlHelper.generateParameterizedInsert(
            table.internalName, columnRow.cells );
        // @ts-ignore
        let insert = alasql.compile( insertCommand );
        if ( ! isDefined( insert ) ) {
            const msg = `Error compiling the insert command at the table "${table.name}".`;
            throw new RuntimeException( msg, table.location );
        }

        // Inserts the values

        for ( let i = 1; i < rowCount; ++i ) { // starts at the second row
            const row = table.rows[ i ];
            try {
                // console.log( 'row', row );
                let params = this.normalizeValues( row.cells, valTypes );
                // console.log( 'params', params );
                insert( params );
            } catch ( e ) {
                const msg = `Error inserting values in the table "${table.name}": ${e.message}`;
github thiagodp / concordialang / modules / db / InMemoryTableCreator.ts View on Github external
const sqlColumns = this._sqlHelper.generateSqlColumns( row.cells, sqlTypes );
                        //console.log( sqlColumns );
                        const createCommand = this._sqlHelper.generateCreateWithTypes( table.name, sqlColumns );

                        try {
                            // Create the table if it does not exist
                            db.exec( createCommand );
                    
                            // Prepare a parameterized insert
                            const insertCommand = this._sqlHelper.generateParameterizedInsert(
                                table.name, row.cells );
                            //console.log( insertCommand );

                            // @ts-ignore
                            insert = alasql.compile( insertCommand );
                        } catch ( e ) {
                            return reject( e );
                        }                        

                    } else {
                        // Create the table if it does not exist
                        const createCommand = this._sqlHelper.generateCreate( table.name, row.cells );
                        //console.log( createCommand );
                        try {
                            db.exec( createCommand );
                        } catch ( e ) {
                            return reject( e );
                        }
                    }

                } else {
github thiagodp / concordialang / dist / modules / db / AlaSqlTableCreator.js View on Github external
const valTypes = this.detectTableColumnTypes(table);
            const sqlTypes = valTypes.map(v => this._sqlHelper.convertToSQLType(v));
            const sqlColumns = this._sqlHelper.generateSqlColumns(columnRow.cells, sqlTypes);
            const createCommand = this._sqlHelper.generateCreateWithTypes(table.internalName, sqlColumns);
            try {
                // console.log( 'TABLE CREATION COMMAND: ', createCommand );
                dbConnection.exec(createCommand); // Creates the table if it does not exist
            }
            catch (e) {
                const msg = `Error creating the table "${table.name}": ${e.message}`;
                throw new error_1.RuntimeException(msg, table.location);
            }
            // Prepares a parameterized insert
            const insertCommand = this._sqlHelper.generateParameterizedInsert(table.internalName, columnRow.cells);
            // @ts-ignore
            let insert = alasql.compile(insertCommand);
            if (!util_1.isDefined(insert)) {
                const msg = `Error compiling the insert command at the table "${table.name}".`;
                throw new error_1.RuntimeException(msg, table.location);
            }
            // Inserts the values
            for (let i = 1; i < rowCount; ++i) { // starts at the second row
                const row = table.rows[i];
                try {
                    // console.log( 'row', row );
                    let params = this.normalizeValues(row.cells, valTypes);
                    // console.log( 'params', params );
                    insert(params);
                }
                catch (e) {
                    const msg = `Error inserting values in the table "${table.name}": ${e.message}`;
                    throw new error_1.RuntimeException(msg, table.location);
github sematext / logagent-js / lib / plugins / output-filter / sql.js View on Github external
if (!config.buffer) {
    config.buffer = {}
    if (config.debug) {
      eventEmitter.on('error', console.error)
    }
  }
  if (!config.buffer[context.sourceName]) {
    config.buffer[context.sourceName] = {
      data: [],
      context: context,
      queries: []
    }
    for (var c in config.queries) {
      var queryStr = config.queries[c]
      try {
        var query = alasql.compile(queryStr)
        config.buffer[context.sourceName].queries.push(query)
      } catch (err) {
        eventEmitter.emit('error', new Error('Error in sql output filter: ' + err.message))
      }
    }
  }
  config.buffer[context.sourceName].data.push(data)
}

alasql

Use SQL to select and filter javascript data - including relational joins and search in nested objects (JSON). Export to and import from Excel and CSV

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis