Open aq1018 opened 4 months ago
For those who stumbled here. I was able to make namespace
style work by doing the following:
function removePublicSchemaPrefix(output) {
for (const path in output) {
const { declarations } = output[path]
declarations.forEach((declaration) => {
const { declarationType, name, properties } = declaration
if (declarationType === 'interface' && name === 'PublicSchema') {
properties.forEach((property) => {
property.name = property.name.replace(/^public\./, '')
})
}
})
}
return output
}
module.exports = {
preRenderHooks: [
makeKyselyHook({ includeSchemaNameInTableName: true }),
removePublicSchemaPrefix,
],
}
Thank you for the kind words and the contribution! This seems like an obvious improvement. As I am not using Kysely myself (I expect that I will in the future), I am not certain of what the most correct answers are and I have been relying on the community for this. I am happy to make this change in the library itself (or accept a PR that does).
I agree with you. The two styles I mentioned are from Kysely documentation, but in reality, different use cases will lead to different design decisions. kanel
with its preRenderHooks
is flexible enough to solve most of my needs. Let's wait for more feedback from Kysely users. This issue is a nice to have, and not urgent ( at least to me ).
First of all. I'd like to say that
kanel
andkanel-kysely
is a great tool with lots of flexibility for type generation, and I'm grateful of the efforts and design put into this awesome project. I'm currently using it in multiple projects in my work. It is great!I'd like to make a suggestion to include a
schemaStyle
option with eithernamespace
ormulti-tenant
values based on the Working with schemas article from Kysely.In it, it posits two ways of using schemas in postgres:
For Option 1,
Database
interface prefixes table names with the schema name, except thepublic
schema. Example:For Option 2,
Database
interface prefixes table names with the schema name only in thepublic
schema. This is because in multi-tenant situation, thepublic
schema holds shared tables for all tenants. Example: