Skip to content

Commit

Permalink
Correct capitalization of JavaScript and TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
DePasqualeOrg committed Apr 26, 2024
1 parent 56af7d7 commit a228fa4
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are quite a few guidelines to keep in mind:

* Kysely should have zero dependencies.

* Kysely should work in all javascript environments (node.js, deno & modern browsers),
* Kysely should work in all JavaScript environments (node.js, deno & modern browsers),
even though the main focus is node.js.

* Everything is immutable.
Expand Down
2 changes: 1 addition & 1 deletion scripts/add-deno-type-references.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This scripts adds a `/// <reference types="./file.d.ts" />` directive
* at the beginning of each ESM javascript file so that they work with
* at the beginning of each ESM JavaScript file so that they work with
* deno.
*/

Expand Down
2 changes: 1 addition & 1 deletion site/docs/examples/SELECT/0110-nested-array.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use the `jsonArrayFrom` helper to fetch person's pets along with the person's id
Please keep in mind that the helpers under the `kysely/helpers` folder, including
`jsonArrayFrom`, are not guaranteed to work with third party dialects. In order for
them to work, the dialect must automatically parse the `json` data type into
javascript JSON values like objects and arrays. Some dialects might simply return
JavaScript JSON values like objects and arrays. Some dialects might simply return
the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
to parse the results.

Expand Down
2 changes: 1 addition & 1 deletion site/docs/examples/SELECT/0120-nested-object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use the `jsonObjectFrom` helper to fetch person's favorite pet along with the pe
Please keep in mind that the helpers under the `kysely/helpers` folder, including
`jsonObjectFrom`, are not guaranteed to work with third-party dialects. In order for
them to work, the dialect must automatically parse the `json` data type into
javascript JSON values like objects and arrays. Some dialects might simply return
JavaScript JSON values like objects and arrays. Some dialects might simply return
the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
to parse the results.

Expand Down
4 changes: 2 additions & 2 deletions site/docs/getting-started/_types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ might differ in naming convention, internal order, etc. Find out more at ["Gener
:::info Runtime types
Kysely only deals with types in the typescript level. The runtime javascript types are decided
Kysely only deals with types in the TypeScript level. The runtime JavaScript types are decided
by the underlying third-party driver such as `pg` or `mysql2` and it's up to you to select the correct
typescript types in the database interface. Kysely never touches the runtime output types in
TypeScript types in the database interface. Kysely never touches the runtime output types in
any way. Find out more at ["Data types"](https://kysely.dev/docs/recipes/data-types).
:::
4 changes: 2 additions & 2 deletions site/docs/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { DemoVideo } from '@site/src/components/DemoVideo'
# Introduction

Kysely (pronounced “Key-Seh-Lee”) is a type-safe and autocompletion-friendly TypeScript SQL query builder. Inspired by Knex. Mainly developed for [node.js](https://nodejs.org/en/) but also
runs on all other javascript environments like [deno](https://deno.land/) and [bun](https://bun.sh/).
runs on all other JavaScript environments like [deno](https://deno.land/) and [bun](https://bun.sh/).

<DemoVideo />

Kysely makes sure you only refer to tables and columns that are visible to the part of the query you're writing. The result type only has the selected columns with correct types and aliases. As an added bonus you get autocompletion for all that stuff.

As shown in the gif above, through the pure magic of modern typescript, Kysely is even able to parse the alias given to `pet.name` and add the `pet_name` column to the result row type. Kysely is able to infer column names, aliases and types from selected subqueries, joined subqueries, `with` statements and pretty much anything you can think of.
As shown in the gif above, through the pure magic of modern TypeScript, Kysely is even able to parse the alias given to `pet.name` and add the `pet_name` column to the result row type. Kysely is able to infer column names, aliases and types from selected subqueries, joined subqueries, `with` statements and pretty much anything you can think of.

Of course there are cases where things cannot be typed at compile time, and Kysely offers escape hatches for these situations. See the [sql template tag](https://kysely-org.github.io/kysely-apidoc/interfaces/Sql.html) and the [DynamicModule](https://kysely-org.github.io/kysely-apidoc/classes/DynamicModule.html#ref) for more info.

Expand Down
16 changes: 8 additions & 8 deletions site/docs/recipes/0002-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
When talking about data types in Kysely we need to make a distinction between the two kinds of types:

1. Typescript types
2. Runtime javascript types
2. Runtime JavaScript types

## Typescript types

In Kysely, you only define typescript types for your tables and columns. Since typescript is entirely a compile-time concept, typescript types __can't__ affect runtime javascript types. If you define your column to be a `string` in typescript but the database returns a `number`, the runtime type doesn't magically change to `string`. You'll see a `string` in the typescript code, but observe a number when you run the program.
In Kysely, you only define TypeScript types for your tables and columns. Since TypeScript is entirely a compile-time concept, TypeScript types __can't__ affect runtime JavaScript types. If you define your column to be a `string` in TypeScript but the database returns a `number`, the runtime type doesn't magically change to `string`. You'll see a `string` in the TypeScript code, but observe a number when you run the program.

:::info
It's up to **you** to select correct typescript types for your columns based on what the driver returns.
It's up to **you** to select correct TypeScript types for your columns based on what the driver returns.
:::

## Runtime javascript types
## Runtime JavaScript types

The database driver, such as `pg` or `mysql2`, decides the runtime javascript types the queries return. Kysely never touches the runtime types the driver returns. In fact, Kysely doesn't touch the data returned by the driver in any way. It simply executes the query and returns whatever the driver returns. An exception to this rule is when you use a plugin like `CamelCasePlugin`, in which case Kysely does change the column names.
The database driver, such as `pg` or `mysql2`, decides the runtime JavaScript types the queries return. Kysely never touches the runtime types the driver returns. In fact, Kysely doesn't touch the data returned by the driver in any way. It simply executes the query and returns whatever the driver returns. An exception to this rule is when you use a plugin like `CamelCasePlugin`, in which case Kysely does change the column names.

You need to read the underlying driver's documentation or otherwise figure out what the driver returns and then align the typescript types to match them.
You need to read the underlying driver's documentation or otherwise figure out what the driver returns and then align the TypeScript types to match them.

### Configuring runtime javascript types
### Configuring runtime JavaScript types

Most drivers provide a way to change the returned types. For example `pg` returns `bigint` and `numeric` types as strings by default, but often you want to configure it to return numbers instead.

Expand Down Expand Up @@ -75,6 +75,6 @@ export const db = new Kysely<Database>({

## Type generators

There are third-party type generators such as [kysely-codegen](https://github.com/RobinBlomberg/kysely-codegen) and [kanel-kysely](https://kristiandupont.github.io/kanel/kanel-kysely.html) that automatically generate typescript types based on the database schema. Find out more at ["Generating types"](https://kysely.dev/docs/generating-types).
There are third-party type generators such as [kysely-codegen](https://github.com/RobinBlomberg/kysely-codegen) and [kanel-kysely](https://kristiandupont.github.io/kanel/kanel-kysely.html) that automatically generate TypeScript types based on the database schema. Find out more at ["Generating types"](https://kysely.dev/docs/generating-types).

If these tools generate a type that doesn't match the runtime type you observe, please refer to their documentation or open an issue in their github. Kysely has no control over these libraries.
2 changes: 1 addition & 1 deletion src/dynamic/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class DynamicModule {
*
* Kysely is built in a way that by default you can't refer to tables or columns
* that are not actually visible in the current query and context. This is all
* done by typescript at compile time, which means that you need to know the
* done by TypeScript at compile time, which means that you need to know the
* columns and tables at compile time. This is not always the case of course.
*
* This method is meant to be used in those cases where the column names
Expand Down
2 changes: 1 addition & 1 deletion src/expression/expression-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ export interface ExpressionBuilder<DB, TB extends keyof DB> {
/**
* Creates a `cast(expr as dataType)` expression.
*
* Since Kysely can't know the mapping between javascript and database types,
* Since Kysely can't know the mapping between JavaScript and database types,
* you need to provide both explicitly.
*
* ### Examples
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Simplify } from '../util/type-utils.js'
* Please keep in mind that the helpers under the `kysely/helpers` folder, including
* `jsonArrayFrom`, are not guaranteed to work with third party dialects. In order for
* them to work, the dialect must automatically parse the `json` data type into
* javascript JSON values like objects and arrays. Some dialects might simply return
* JavaScript JSON values like objects and arrays. Some dialects might simply return
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
* to parse the results.
*
Expand Down Expand Up @@ -74,7 +74,7 @@ export function jsonArrayFrom<O>(
* Please keep in mind that the helpers under the `kysely/helpers` folder, including
* `jsonObjectFrom`, are not guaranteed to work with third-party dialects. In order for
* them to work, the dialect must automatically parse the `json` data type into
* javascript JSON values like objects and arrays. Some dialects might simply return
* JavaScript JSON values like objects and arrays. Some dialects might simply return
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
* to parse the results.
*
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/camel-case/camel-case-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface CamelCasePluginOptions {

/**
* A plugin that converts snake_case identifiers in the database into
* camelCase in the javascript side.
* camelCase in the JavaScript side.
*
* For example let's assume we have a table called `person_table`
* with columns `first_name` and `last_name` in the database. When
Expand Down Expand Up @@ -91,7 +91,7 @@ export interface CamelCasePluginOptions {
* ```
*
* As you can see from the example, __everything__ needs to be defined
* in camelCase in the typescript code: table names, columns, schemas,
* in camelCase in the TypeScript code: table names, columns, schemas,
* __everything__. When using the `CamelCasePlugin` Kysely works as if
* the database was defined in camelCase.
*
Expand Down
6 changes: 3 additions & 3 deletions src/query-builder/delete-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,17 +959,17 @@ export class DeleteQueryBuilder<DB, TB extends keyof DB, O>
/**
* Asserts that query's output row type equals the given type `T`.
*
* This method can be used to simplify excessively complex types to make typescript happy
* This method can be used to simplify excessively complex types to make TypeScript happy
* and much faster.
*
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
* for typescript and you get errors like this:
* for TypeScript and you get errors like this:
*
* ```
* error TS2589: Type instantiation is excessively deep and possibly infinite.
* ```
*
* In these case you can often use this method to help typescript a little bit. When you use this
* In these case you can often use this method to help TypeScript a little bit. When you use this
* method to assert the output type of a query, Kysely can drop the complex output type that
* consists of multiple nested helper types and replace it with the simple asserted type.
*
Expand Down
8 changes: 4 additions & 4 deletions src/query-builder/function-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* If this function is used in a `select` statement, the type of the selected
* expression will be `number | string` by default. This is because Kysely can't know the
* type the db driver outputs. Sometimes the output can be larger than the largest
* javascript number and a string is returned instead. Most drivers allow you
* JavaScript number and a string is returned instead. Most drivers allow you
* to configure the output type of large numbers and Kysely can't know if you've
* done so.
*
Expand Down Expand Up @@ -371,7 +371,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* If this function is used in a `select` statement, the type of the selected
* expression will be `number | string | bigint` by default. This is because
* Kysely can't know the type the db driver outputs. Sometimes the output can
* be larger than the largest javascript number and a string is returned instead.
* be larger than the largest JavaScript number and a string is returned instead.
* Most drivers allow you to configure the output type of large numbers and Kysely
* can't know if you've done so.
*
Expand Down Expand Up @@ -429,7 +429,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* If this is used in a `select` statement, the type of the selected expression
* will be `number | string | bigint` by default. This is because Kysely
* can't know the type the db driver outputs. Sometimes the output can be larger
* than the largest javascript number and a string is returned instead. Most
* than the largest JavaScript number and a string is returned instead. Most
* drivers allow you to configure the output type of large numbers and Kysely
* can't know if you've done so.
*
Expand Down Expand Up @@ -630,7 +630,7 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* If this function is used in a `select` statement, the type of the selected
* expression will be `number | string` by default. This is because Kysely can't know the
* type the db driver outputs. Sometimes the output can be larger than the largest
* javascript number and a string is returned instead. Most drivers allow you
* JavaScript number and a string is returned instead. Most drivers allow you
* to configure the output type of large numbers and Kysely can't know if you've
* done so.
*
Expand Down
6 changes: 3 additions & 3 deletions src/query-builder/insert-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,17 +881,17 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
/**
* Asserts that query's output row type equals the given type `T`.
*
* This method can be used to simplify excessively complex types to make typescript happy
* This method can be used to simplify excessively complex types to make TypeScript happy
* and much faster.
*
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
* for typescript and you get errors like this:
* for TypeScript and you get errors like this:
*
* ```
* error TS2589: Type instantiation is excessively deep and possibly infinite.
* ```
*
* In these case you can often use this method to help typescript a little bit. When you use this
* In these case you can often use this method to help TypeScript a little bit. When you use this
* method to assert the output type of a query, Kysely can drop the complex output type that
* consists of multiple nested helper types and replace it with the simple asserted type.
*
Expand Down
8 changes: 4 additions & 4 deletions src/query-builder/select-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
/**
* Call `func(this)` if `condition` is true.
*
* NOTE: This method has an impact on typescript performance and it should only be used
* NOTE: This method has an impact on TypeScript performance and it should only be used
* when necessary. Remember that you can call most methods like `where` conditionally
* like this:
*
Expand Down Expand Up @@ -1777,17 +1777,17 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
/**
* Asserts that query's output row type equals the given type `T`.
*
* This method can be used to simplify excessively complex types to make typescript happy
* This method can be used to simplify excessively complex types to make TypeScript happy
* and much faster.
*
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
* for typescript and you get errors like this:
* for TypeScript and you get errors like this:
*
* ```
* error TS2589: Type instantiation is excessively deep and possibly infinite.
* ```
*
* In these case you can often use this method to help typescript a little bit. When you use this
* In these case you can often use this method to help TypeScript a little bit. When you use this
* method to assert the output type of a query, Kysely can drop the complex output type that
* consists of multiple nested helper types and replace it with the simple asserted type.
*
Expand Down
6 changes: 3 additions & 3 deletions src/query-builder/update-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,17 +908,17 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
/**
* Asserts that query's output row type equals the given type `T`.
*
* This method can be used to simplify excessively complex types to make typescript happy
* This method can be used to simplify excessively complex types to make TypeScript happy
* and much faster.
*
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
* for typescript and you get errors like this:
* for TypeScript and you get errors like this:
*
* ```
* error TS2589: Type instantiation is excessively deep and possibly infinite.
* ```
*
* In these case you can often use this method to help typescript a little bit. When you use this
* In these case you can often use this method to help TypeScript a little bit. When you use this
* method to assert the output type of a query, Kysely can drop the complex output type that
* consists of multiple nested helper types and replace it with the simple asserted type.
*
Expand Down

0 comments on commit a228fa4

Please sign in to comment.