Issue while extracting init logic to separate module
See original GitHub issueHi. I’ve been checking this tool for a few days and find it amazing, thanks!!
I’m developing a serverless application that will deploy a number of different lambdas, many of which need to access kyselys functionalities. For that, I want to extract the init logic new Kysely<Database>{...}
to a reusable method which can be called from the different functions that require it.
My current codebase is as follows
const createDBConnection = () => new Kysely<SilverTables>({
dialect: new MysqlDialect({
// Empty pool configuration. Pool is mandatory to instantiate a Kysely object.
// We won't be relying on Kysely to execute the query, only to build it.
pool: createPool({}),
})
})
const db = createDBConnection();
//entry point
const handler: Handler<APIGatewayEvent, ReturnType> = async (event) => {
const queryBuilder = createQueryBuilder('1');
const queryResult = await executeQuery(queryBuilder);
return queryResult;
}
const createQueryBuilder = (id: string) => db.selectFrom('table).where('id', '=', id).select(['column']);
const executeQuery = <DB, TB extends keyof DB, O>(queryBuilder: SelectQueryBuilder<DB, TB, O>): Promise<O[]> => {
const compiledQuery = queryBuilder.compile();
let queryString = compiledQuery.sql;
const params = compiledQuery.parameters;
for (const param of params)
queryString = queryString.replace('?', String(param));
return dataAccessAPI(queryString);
}
If if move the createDBConnection
method to a separate module, I start getting the following error: Property '#private' in type 'SelectQueryBuilder' refers to a different member that cannot be accessed from within type 'SelectQueryBuilder'.
. Any ideas?
Thanks in advance
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Extractor using Function Module - distinguish between INIT ...
When looking at this function module, the logic seems to utilize values in the parameter I_UPDMODE from Type Group SBIWA to make the ......
Read more >python - Module imports and __init__.py - Stack Overflow
What I mean is that when the script Foo.py is run it will import everything it can and then __init__.py will be called...
Read more >5. Separation of Concerns - Programming JavaScript ... - O'Reilly
Separation of concerns is the idea that each module or layer in an application should only be responsible for one thing and should...
Read more >What's __init__ for me? Designing for Python package imports
I have had a few conversations lately about Python packaging, particularly around structuring the import statements to access the various ...
Read more >Component Reference - Apache JMeter - User's Manual
Several test elements use JMeter properties to control their behaviour. These properties are normally resolved when the class is loaded.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One thing that could cause problems like this is if you have two copies of Kysely installed and you try to use them together. For example if the module that exports
createDBConnection
imports a different version of Kysely than the place that uses it, you’d get an error like that.Make sure that’s not happening. If you’re not able to do that otherwise, something like this should give you the answer:
This is a little bit off topic, but regarding the
createDBConnection
function: you don’t need to create a dummy mysql pool. You can do this instead:This way your module doesn’t depend on the
mysql2
module at all. All of those classes can be imported fromkysely
.