Closed deepakpenjarla closed 4 years ago
Obviously, its not done yet, but I've been using this in my Typescript projects so the TS compiler won't yell at me, so it might help you:
Saving this as idb-connector.d.ts and puting it at the root of my project works.
// Type definitions for [~PROJECT NAME~]
// Project: [~THE PROJECT NAME~]
// Definitions by: [~YOUR NAME~]
/*~ This is the module template file. You should rename it to index.d.ts
*~ and place it in a folder with the same name as the module.
*~ For example, if you were writing a file for "super-greeter", this
*~ file should be 'super-greeter/index.d.ts'
*/
declare module 'idb-connector' {
export class dbconn {
/**
* Set an attribute of a specific connection handle.
*
* [Refer to this link for information about connection attributes.](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/cli/rzadpfngcona.htm)
*/
setConnAttr(attribute: number, value: number | string): boolean;
/**
* Returns the current settings for the specified connection attribute.
*
* [Refer to this link for information about connection attributes.](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/cli/rzadpfngcona.htm)
*/
getConnAttr(attribute: number): number | string;
/**
* Establishes a connection to the target database.
*/
conn(database: string): void;
conn(database: string, callback: () => void): void;
conn(database: string, callback: () => void): void;
conn(database: string, user: string, password: string, callback: () => void): void;
conn(database: string, user: string, password: string): void;
/**
* Toggles verbose debugging log
*/
debug(flag: boolean): void;
/**
* Ends the connection associated with the database connection handle.
* After calling this function, either call `conn` to connect to another database or `close`.
*/
disconn(): boolean;
/**
* Frees all DB2 for i resources associated with the connection object.
* `disconn()` must be called before calling this function.
*/
close(): boolean;
/** Checks if the SQL string is valid and interprets vendor escape clauses.
*
* If the original SQL string that is passed by the application contains vendor escape clause sequences,
* DB2 for i CLI returns the transformed SQL string that is seen by the data source
* (with vendor escape clauses either converted or discarded as appropriate).*/
validStmt(sql: string): string;
}
export class dbstmt {
constructor(dbconn: dbconn);
/**
* Asynchronously runs the specified SQL statement.
*/
exec(sql: string, callback: (resultSet: object[], error: Error | null) => void): void;
asNumber(flag: boolean): boolean;
/**
* DB2 for i resources associated with the statement object are freed.
* The open cursor, if any, is closed and all pending results are discarded.
*
* @example
* stmt.exec('...', (results, error) => {
* stmt.close();
* return result
* })
*
*/
close(): void;
/**
* Synchronus version of `exec`
*/
execSync(sql: string, callback: (resultSet: object[], error: Error | null) => void): void;
}
}
I'd love to be corrected, but getting the types out of the C++ header files and into a types definitions file is non-trivial because of how .d files are derived in the first place: from .ts files. Which means the project would have to be written in Typescript. And its not. It's written in C++. Which I guess means the type files would have to be done by hand.
There's a project called nbind that takes C++ files and does something to get .d files, but I'm just a smooth-brained JS dev and C++ scares me.
Many thanks @sgrezza.. Let me try using this in my project. Have you used itoolkit also in your project.?
I tried using idb-connector.d.ts file, I copied it to root path and tried accessing in one ts file. It compiled successfully but I am getting "Uncaught ReferenceError: require is not defined" error in Browser console at line:15 (const i_xml = require('./ixml');) in itoolkit.js.
Tried declaring 'require' in my .ts file as 'declare var require: any;' but still no result. I am completely new to Angular. It would be great if you elaborate using idb-connector in Angular.?
I've never used itoolkit, but the issue I think you're having is that 'require' is a Nodejs thing, so you need Webpack or Rollup or something to build your code for a browser (which Angular already has; not sure what your issue is).
Anyway, I'm going to guess that IDB-connector or itoolkit is not going to work in an Angular project because Angular is meant to be ran in the browser, and IDB-connector only runs on Series i.
Yes Correct, IDB-connector only runs on iSeries. We have a Node JS project that runs on iSeries (without any issues) where idb-connector is used for DB2 connection/fetching the data. Now, the requirement is to make DB2 connectivity with an Angular Application (running on iSeries).
The question here is,, Is it possible to make use of idb-connector to do it ?? or is there any other way to do DB2 connection/fetching the data .?
Could you please elaborate how could I make use of idb-conector.d.ts file for fetching the data.?
Thanks...
To be clear: .d.ts files have no actual functionality in them; Typescript just wants them so it can do type checking for their respective packages. As for getting data into an Angular app: we have our Angular apps hit an Express endpoint running on our iSeries. The Express app then does all the setup for creating a query statement, runs a specified query, then sends back the data.
Just a correction: idb-connector has never run on either System i or iSeries, only IBM i. :wink:
As far as TypeScript support goes, we are not using TS ourselves, but if someone submitted a PR with TS support, that'd be awesome.
:wave: Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.
We are trying to use idb-connector in an angular project but couldn't. We are not able to find its corresponding @types file. Could you please provide.?
Please provide a workaround to use this.
++ @ThePrez