it('promise and await/async', async () => { const rows = await clickhouse.query(sql).toPromise(); expect(rows).to.have.length(rowCount); expect(rows[0]).to.eql({ number: 0, str: '0', date: '1970-01-02' }); });
it('callback #1', callback => { clickhouse.query(sql).exec((err, rows) => { expect(err).to.not.be.ok(); expect(rows).to.have.length(rowCount); expect(rows[0]).to.eql({ number: 0, str: '0', date: '1970-01-02' }); callback(); }); });
it('listFunctions should ok', async function () { var response = await client.listFunctions(serviceName); expect(response.data).to.be.ok(); expect(response.data.functions).to.be.ok(); expect(response.data.functions).to.have.length(2); var func = response.data.functions; expect(func[0]).to.have.property('functionName', initFunctionName); expect(func[1]).to.have.property('functionName', functionName); response = await client.listFunctions(serviceName, {}, {}, 'LATEST'); expect(response.data).to.be.ok(); expect(response.data.functions).to.be.ok(); expect(response.data.functions).to.have.length(2); func = response.data.functions; expect(func[0]).to.have.property('functionName', initFunctionName); expect(func[1]).to.have.property('functionName', functionName); });
it('callback #2', callback => { clickhouse.query(sql, (err, rows) => { expect(err).to.not.be.ok(); expect(rows).to.have.length(rowCount); expect(rows[0]).to.eql({ number: 0, str: '0', date: '1970-01-02' }); callback(); }); });
it('select with external', async () => { const result = await clickhouse.query( 'SELECT count(*) AS count FROM temp_table', { external: [ { name: 'temp_table', data: _.range(0, rowCount).map(i => `str${i}`) }, ] } ).toPromise(); expect(result).to.be.ok(); expect(result).to.have.length(1); expect(result[0]).to.have.key('count'); expect(result[0].count).to.be(rowCount); });
return instance._addMigrationRow(1, '2018_12_03_03_05_12').then(() => { return instance.getMigrationRows().then(list => { expect(list).to.have.length(1); }); }); return instance._removeMigrationRow('2018_12_03_03_05_12').then(() => { return instance.getMigrationRows().then(list => { expect(list).to.have.length(0); }); });
expect(result).to.eql(undefined); return instance.getMigrationFiles().then(files => { expect(files).to.have.length(1); }); });
const res = await client.listVersions(serviceName); expect(res.data.versions).to.have.length(1); expect(res.data.versions[0].versionId).to.be('2'); });
const rows = await clickhouse.query(fullSql).toPromise(); expect(rows).to.have.length(rowCount); expect(rows[0]).to.eql({ number: 0, str: '0', date: '1970-01-02' }); }); const rows = await clickhouse.query(sql, {}, { format }).toPromise(); expect(rows).to.have.length(rowCount); expect(rows[0]).to.eql({ number: 0, str: '0', date: '1970-01-02' }); });
expect(response.data).to.be.ok(); expect(response.data.triggers).to.be.ok(); expect(response.data.triggers).to.have.length(1); const [trigger] = response.data.triggers; expect(trigger).to.have.property('triggerName', triggerName);
it('should generate a currect date string', function() { const date_string = helpers.createDateStr(); expect(date_string).to.have.length(19); }); }); const migration_file_name = helpers.createMigrationFileName(); const date_string = helpers.createDateStr(); expect(date_string).to.have.length(migration_file_name.length); }); });
'tableName', 'schema.columns', 'schema.collation' ]); expect( errors['schema.columns'] ).to.have.length(1); expect( errors['schema.columns'][0] ).to.only.have.keys([ 'invalid_type', 'invalid_charset', 'invalidName'
it('select with external && join', async () => { const result = await clickhouse.query( ` SELECT * FROM system.numbers AS i LEFT JOIN ( SELECT number FROM system.numbers WHERE number IN temp_table LIMIT 10 ) AS n ON(n.number = i.number) LIMIT 100 `, { external: [ { name: 'temp_table', data: _.range(0, 10), structure: 'i UInt64' }, ] } ).toPromise(); expect(result).to.be.ok(); expect(result).to.have.length(100); });