Are there flowtype definitions for alasql?
There is no flowtype definition for alasql at the moment.
If you would like to help me test, I would love to make one in cooperation with you...
@karubimania would you be interested in testing if I make a flowtype definition?
@mathiasrw I missed your original response, yes I could contribute some test scripts. In the interim the easiest way to test is to run flow check. It won't confirm for integration tests but it should pick up on small errors
We should make it work, and then make a PR to https://github.com/flowtype/flow-typed/ so its in the ecosystem.
I imagine we also place it in this repo so when build it gets placed in dist/together with the original lib file.
Ok - I have made a version - but not been able to setup the whole flow eco system, so I would be happy if you could test this out.
alasql.js.flow and insert the following:declare namespace alaSQLSpace {
interface AlaSQLCallback {
(data?: any, err?: Error): void;
}
interface AlaSQLOptions {
errorlog: boolean;
valueof: boolean;
dropifnotexists: boolean; // drop database in any case
datetimeformat: string; // how to handle DATE and DATETIME types
casesensitive: boolean; // table and column names are case sensitive and converted to lower-case
logtarget: string; // target for log. Values: 'console', 'output', 'id' of html tag
logprompt: boolean; // print SQL at log
modifier: any; // values: RECORDSET, VALUE, ROW, COLUMN, MATRIX, TEXTSTRING, INDEX
columnlookup: number; // how many rows to lookup to define columns
autovertex: boolean; // create vertex if not found
usedbo: boolean; // use dbo as current database (for partial T-SQL comaptibility)
autocommit: boolean; // the AUTOCOMMIT ON | OFF
cache: boolean; // use cache
nocount: boolean; // for SET NOCOUNT OFF
nan: boolean; // check for NaN and convert it to undefined
angularjs: boolean;
tsql: boolean;
mysql: boolean;
postgres: boolean;
oracle: boolean;
sqlite: boolean;
orientdb: boolean;
}
// compiled Statement
interface AlaSQLStatement {
(params?: any, cb?: AlaSQLCallback, scope?: any): any;
}
// abstract Syntax Tree
interface AlaSQLAST {
compile(databaseid: string): AlaSQLStatement;
}
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts
interface Thenable<T> {
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
catch<U>(onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
}
// see https://github.com/agershun/alasql/wiki/User%20Defined%20Functions
interface userDefinedFunction {
(x: any): any;
}
interface userDefinedFunctionLookUp {
[x: string]: userDefinedFunction;
}
// see https://github.com/agershun/alasql/wiki/User%20Defined%20Functions
interface userAggregator {
(value: any, accumulator: any, stage: number): any;
}
interface userAggregatorLookUp {
[x: string]: userAggregator;
}
interface AlaSQL {
(sql: any, params?: any, cb?: AlaSQLCallback): any;
options: AlaSQLOptions;
error: Error;
parse(sql): AlaSQLAST;
promise(sql: any, params?: any): Thenable<any>;
fn: userDefinedFunctionLookUp;
aggr: userAggregatorLookUp;
autoval(tablename: string, colname: string, getNext?:boolean): number;
}
}
declare var alasql: alaSQLSpace.AlaSQL;
declare module 'alasql' {
export = alasql;
}
Let me know if it works. If now I will have to dig more into getting flow up and running.
@mathiasrw thanks for doing this! There are some errors:
namespace isn't a thing in flow, I would just prefix alasql-internal stuff with _alasql_
the module export construct should be something like
declare module 'alasql' {
declare var exports:AlaSQL;
}
You don't need to install anything to test, just go to https://flowtype.org/try/ and paste just the alasql.js.flow code
Perfect with the website to test. I made a PR to add the definition: https://github.com/flowtype/flow-typed/pull/669
If you would like to make the test files better (or edit in the definition) you can:
definitions/npm/alasql..../run_def_tests.sh alasql
Most helpful comment
We should make it work, and then make a PR to https://github.com/flowtype/flow-typed/ so its in the ecosystem.
I imagine we also place it in this repo so when build it gets placed in
dist/together with the original lib file.Ok - I have made a version - but not been able to setup the whole flow eco system, so I would be happy if you could test this out.
alasql.js.flowand insert the following:Let me know if it works. If now I will have to dig more into getting flow up and running.