Git Product home page Git Product logo

Comments (9)

isaru66 avatar isaru66 commented on June 1, 2024 1

@dhensby thank for your suggestion.

I have change the code in TypeORM, once multSubnetFailover option get added to SqlServerConnectionOptions. After the change, the multSubnetFailover option will be passed down from TypeORM => NodeMSSQL => TediosJS correctly.

I have create a pull request in TypeORM as typeorm/typeorm#10804

from node-mssql.

dhensby avatar dhensby commented on June 1, 2024

I'm not sure what the extra prop is meant to be, we don't support that as part of our config object at all.

The way to pass options directly to tedious is using the options prop (as you are for trustServerCertificate).

I don't know about tedious' underlying support for the option (I don't see it in the link you provided), which is going to be what decides if it is supported or not.


edit: I was only my phone when initially reviewing this and didn't realise you were linking to the node-mssql connection code and not tedious.

Tedious does accept the option: https://github.com/tediousjs/tedious/blob/7e84a2f54c6cb983b18a75ad1fc4bf274b2398e5/src/connection.ts#L377 - so it just needs to be set appropriately:

export const AppDataSource = new DataSource({
    type: "mssql",
    host: "localhost",
    username: "sa",
    password: "***",
    database: "test",
    synchronize: false,
    logging: false,
    entities: [User],
    migrations: [],
    subscribers: [],
    options: {
+        multiSubnetFailover: true,
        trustServerCertificate: true
    },
-    extra: {
-        multiSubnetFailover: true
-    }
})

from node-mssql.

isaru66 avatar isaru66 commented on June 1, 2024

@dhensby , I worked with @ibm-mai . Currently the issue is that node-mssql did not pass the multiSubnetFailover to tediosjs.

I have open PR #1626 to resolve this issue.

from node-mssql.

isaru66 avatar isaru66 commented on June 1, 2024

from TypeORM, option prop is type check with
https://github.com/typeorm/typeorm/blob/83567f533482d0170c35e2f99e627962b8f99a08/src/driver/sqlserver/SqlServerConnectionOptions.ts , and currently SqlServerConnectionOptions.ts does not have multiSubnetFailover, thus we cannot add multiSubnetFailover in TypeORM option yet, since it will violate type-checking.

extra prop is custom properties with any type, thus it allow us to pass any property that may not yet defined in SqlServerConnectionOptions.ts, we can see from the below source code of TypeORM that extra prob will be merge with options prop to construct options for NodeMSSQL.
https://github.com/typeorm/typeorm/blob/83567f533482d0170c35e2f99e627962b8f99a08/src/driver/sqlserver/SqlServerDriver.ts#L1100

from node-mssql.

dhensby avatar dhensby commented on June 1, 2024

Can you elaborate on the extra prop is merged with the base object and not the options sub object, which is where it is needed.

You can coerce types in typescript so you can add arbitrary props. Eg: value as unknown as Interface

from node-mssql.

isaru66 avatar isaru66 commented on June 1, 2024

@dhensby

to elaborate that options and extra prop get merged in TypeORM before send to Node-MSSQL.

let say in TypeORM we construct datasource with both trustServerCertificate and multiSubnetFailover in extra section only

export const AppDataSource = new DataSource({
    type: "mssql",
    host: "127.0.0.1",
    username: "sa",
    password: "Passwd@1234",
    database: "tempdb",
    synchronize: true,
    logging: false,
    entities: [User],
    migrations: [],
    subscribers: [],
    extra: {
        trustServerCertificate: true,  
        multiSubnetFailover: true,
    }
})

Once I ran this code and set break point at TypeORM SqlServerDriver.js , function createPool().
image

We can see that the connectionOptions is the merged value between options and extra prop
image
this is the value that TypeORM send to node-mssql.

image

so... using extra option in TypeORM is able to pass multiSubnetFailover option to node-mssql.

from node-mssql.

isaru66 avatar isaru66 commented on June 1, 2024

the current issue is that mssql.ConnectionPool(connectionOptions) in node-mssql did not passed down multiSubnetFailover option to tediusjs driver currently.

That why i create the PR to try to fix this issue.

from node-mssql.

dhensby avatar dhensby commented on June 1, 2024

This library does not support the property multiSubnetFailover in the config object. If you want to provide that value to tedious it must be done in the options sub-object in the config.

There is no problem here and I'm quite confused as to why my solution is not satisfactory.

If TypeORM has issues with the typing for the DB config object, then those typings need fixing instead of expanding the API surface of this library.

export const AppDataSource = new DataSource({
    type: "mssql",
    host: "localhost",
    username: "sa",
    password: "***",
    database: "test",
    synchronize: false,
    logging: false,
    entities: [User],
    migrations: [],
    subscribers: [],
    options: {
        multiSubnetFailover: true,
        trustServerCertificate: true
    },
} as unknown as SqlServerConnectionOptions);

Better yet, open a PR there to fix SqlServerConnectionOptions

from node-mssql.

dhensby avatar dhensby commented on June 1, 2024

Also, just to add (for sake of clarity) your example of adding trustServerCertificate to extra will also not work because it must be in the the options sub-object not the root level. Your solution in the linked PR is not scalable or reasonable as a solution as the natural conclusion is that every property that is added in the root object be duplicated in the options just to allow TypeORM to add these values in the extra object...

Fix the upstream library, don't add one-off "fixes" to this library to support the narrow implementation of TypeORM.

from node-mssql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.