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

Enhancement: Parsed connection strings proxy #5

Open
dhensby opened this issue Jan 25, 2021 · 0 comments
Open

Enhancement: Parsed connection strings proxy #5

dhensby opened this issue Jan 25, 2021 · 0 comments

Comments

@dhensby
Copy link
Collaborator

dhensby commented Jan 25, 2021

see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

Ideally a connection object should add some layer of abstraction around the parsed connection string. This would result in more than a simple map of key value pairs being returned and instead the object being queried and parsed in a more helpful way.

eg:

const { parseSqlConnectionString } = require('@tediousjs/connection-string');
const connStr = "Data Source=tcp:mydomain.com,1433";

const connectionObj = parseSqlConnectionString(connStr);

console.log(connectionObj.host); // mydomain.com
console.log(connectionObj.port); // 1433
console.log(connectionObj.proto); // tcp
console.log(connectionObj['data source']); // tcp:mydomain.com,1433
console.log(connectionObj.Addr); // tcp:mydomain.com,1433

This could be implemented as

const connStr = "Data Source=tcp:mydomain.com,1433";
const connectionObj = parseSqlConnectionString(connStr);
return new Proxy(connectionObj, {
    get: (target, prop, receiver) => {
        // special handling for some cases like alias props
        // special handling for computed props (eg: host, proto, port)
        // return case insensitive look up
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant