Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Definition now available for 4.0 #1136

Closed
connorjayfitzgerald opened this issue Aug 6, 2019 · 16 comments
Closed

Typescript Definition now available for 4.0 #1136

connorjayfitzgerald opened this issue Aug 6, 2019 · 16 comments

Comments

@connorjayfitzgerald
Copy link

The DefinitelyTyped definition for oracledb 4.0 has now been merged and is available to use.

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oracledb

@connorjayfitzgerald
Copy link
Author

One thing to note...

Due to the refactoring in 4.0, using both default and named exports will result in the named exports being undefined.

For example:

import oracledb, { OUT_FORMAT_OBJECT } from 'oracledb';

This will result in OUT_FORMAT_OBJECT being undefined.
Instead, separate out the default and named imports, like so:

import oracledb from 'oracledb';
import { OUT_FORMAT_OBJECT } from 'oracledb';

See here for reference

@sosoba
Copy link

sosoba commented Aug 19, 2019

Have you considered enriching the declaration with generic types for the result (with default Row type). Something like:

interface Result<R> {
  rows: R[];
}
        
execute<R=Row>(sql: string, bindParams: BindParameters, options: ExecuteOptions): Promise<Result<R>>;

this would allow queries to be typed:

   const res = await connection.execute<{X:string}>( 'SELECT X from DUAL' );

@connorjayfitzgerald
Copy link
Author

connorjayfitzgerald commented Aug 19, 2019

Good idea!

See PR #37747

@sosoba
Copy link

sosoba commented Aug 28, 2019

I don't know if this is a good place for further comments.
oracledb@4 added a new

dbTypeName

attribute to MetaData result. Type - string, It contains the name of the type the column has in the database, such as "VARCHAR2".

@connorjayfitzgerald
Copy link
Author

connorjayfitzgerald commented Aug 28, 2019

@sosoba

These missing properties will be added in PR #38035

@sosoba
Copy link

sosoba commented Sep 17, 2019

I have a litle issue: Record in line 581:

type BindParameters = Record<string, BindParameter | string | number | Date | DBObject | Buffer | null> | BindParameter[] | any[];

should also prevent undefined because oracledb@4treats them as null.

@connorjayfitzgerald
Copy link
Author

@sosoba Could you send me a code snippet as I'm not sure what you mean?

The types do currently prevent bind parameters being undefined

@sosoba
Copy link

sosoba commented Sep 19, 2019

This js snippet print "1" because oracledb allow to pass undefined as null-value parameter:

const oracledb  = require('oracledb');

(async function(){

  const conn = await oracledb.getConnection({user:'TEST',password:'TEST',connectString:'localhost:1521/XE'});
  const res = await conn.execute('SELECT * FROM DUAL where :p1 is null and :p2 is null', {
    p1:null, 
    p2:undefined,
  });
  console.log(res.rows.length);

})();

Type definition for BindParameters treats it as a mistake.

@connorjayfitzgerald
Copy link
Author

It’s correct to flag it as a mistake, as oracledb ignores undefined bind parameters. You’ll get an error saying not all variables bound.

You can test this by doing
{
p1: null,
p2: undefined as any
}

@sosoba
Copy link

sosoba commented Sep 20, 2019

I'm trying again:

{
   p1: null,
}

give me ORA-01008 : Not all variables bound, but

{
   p1: null,
   p2: undefined as any
}

give me success. Oracledb translate undefined to null.

Object.keys( { p1 : null, p2 : undefined } ); // [ 'p1', 'p2' ]

@connorjayfitzgerald
Copy link
Author

Just tried again and you're right, it was treated as null. I'm sure I tried that yesterday!
This will be fixed in #38496

@sosoba
Copy link

sosoba commented Sep 20, 2019

Thank you.

@sosoba
Copy link

sosoba commented Sep 24, 2019

I have a doubt about oracledb-tests.ts. Assert at line 160:

 assert.deepStrictEqual(row, [1]);

is based on select without order by statement and it seems to me that there is no guarantee that database engine will allways return one in first row.

@sosoba
Copy link

sosoba commented Oct 25, 2019

Regadles to documentation:

The default value for extendedMetaData is false. With this value, the result.metaData result.resultSet.metaData objects only include column names.

Could you add question marks to other fields than name in interface Metadata ?

@cjbj
Copy link
Member

cjbj commented Dec 10, 2019

Updates for node-oracledb 4.1 got merged: DefinitelyTyped/DefinitelyTyped#40653

Thank you @connorjayfitzgerald !

@cjbj
Copy link
Member

cjbj commented Jul 5, 2020

@connorjayfitzgerald has got a TypeScript PR ready for node-oracledb 5: DefinitelyTyped/DefinitelyTyped#45781

I think I'll close this old announcement issue - otherwise it could remain open forever!

@cjbj cjbj closed this as completed Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants