Comments (9)
It's not possible to make that work.
from kysely.
this is a bug, idk why it got closed.
from kysely.
create table company
(
id integer generated by default as identity
constraint company_pk
primary key,
amount_spend_12m int
);
you can try this ddl with camelcase plugin
There are two way to type this table.
interface Company {
amountSpend12m: string
}
const rows = db
.selectFrom('company')
.select('amountSpend12m')
.compile()
// compiles to `select "amount_spend12m" from "company"`;
// this query produce error because amount_spend12m is not defined
interface Company {
amountSpend_12m: string
}
const rows = db
.selectFrom('company')
.select('amountSpend_12m')
.compile()
// compiles to `select "amount_spend_12m" from "company"`;
// the result actual shape is { amountSpend12m: number } but kysely infer it as { amountSpend_12m: number }
How should we type such table? I already rename the column to something else without numbers, but this should be a bug in my opinion
from kysely.
The camel case plugin simply runs all identifiers (column names, table names etc.) through a toSnakeCase
function and then the returned column names through a toCamelCase
function. When kysely receives a column named amount_spend_12m
from the db, how could it possibly know that it's supposed to transform it to a mixture of cameCase and snake_case amountSpend_12m
?
We don't actually know which select
s map to which returned columns. Figuring that out would be super difficult.
You can override the CamelCasePlugin
:
class MyCamelCasePlugin extends CamelCasePlugin {
protected override camelCase(str: string): string {
if (str === 'amount_spend_12m') {
return 'amountSpend_12m'
}
return super.camelCase(str)
}
}
but it's not possible to make the default work the way you want. For example, how would Kysely know what to do when you run selectFrom('company').selectAll().limit(1).execute()
?
from kysely.
if the column name is amount_spend_12m
, how should user define it in typescript interface?
from kysely.
amountSpend12m
from kysely.
it doesn't work. kysely transform it to amount_spend12m
from kysely.
See the documentation https://koskimas.github.io/kysely/interfaces/CamelCasePluginOptions.html#underscoreBeforeDigits
from kysely.
And you're welcome for the free help once again!
from kysely.
Related Issues (20)
- Question on postgresql query-level variables HOT 2
- Filtering by the result returned by subquery HOT 4
- [MySQL] Incorrect placement of CTEs in INSERT/REPLACE INTO ... SELECT queries HOT 1
- ColumnType for where clause HOT 1
- support for functions in selectFrom, e.g. GENERATE_SERIES HOT 1
- Schema-based migrations for multi-tenant support HOT 1
- Alter sequence with builder?
- Deno docs bug HOT 1
- Merge Query joins `WhenNode`s with comma which causes a syntax error
- Error with returning when insertInto HOT 1
- Exporting query builder classes
- ColumnDefinitionBuilder.ifNotExists() not yet available HOT 2
- Support postgres array data types HOT 2
- `as` required in subquery although it does not add to type-safety HOT 3
- Request: CLI migrations tool for Deno HOT 8
- Hiding certain property when using jsonArrayFrom HOT 1
- Is it possible to tell from an onDuplicateKeyUpdate whether it was created or updated? HOT 1
- Update to set boolean value to opposite value HOT 6
- Attempting to rollback a connection that fails to get created HOT 1
- executeTakeFirstOrThrow includes the query node in the error by default HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kysely.