Skip to content

Commit

Permalink
add support for recursive CTE. closes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Dec 21, 2021
1 parent b977bd9 commit e8b3120
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand Down
128 changes: 49 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "kysely",
"version": "0.12.1",
"version": "0.12.2",
"description": "Type safe SQL query builder",
"repository": {
"type": "git",
"url": "git://github.com/koskimas/kysely.git"
},
"engines": {
"node": ">=16.0.0"
"node": ">=14.0.0"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
16 changes: 9 additions & 7 deletions scripts/copy-interface-documentation.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* This script goes through all generated type definition files and copies
* method documentation from interfaces to the implementing methods IF
* the implementation doesn't have its own documentation.
* method/property documentation from interfaces to the implementing methods
* IF the implementation doesn't have its own documentation.
*
* This is done for convenience: users can cmd-click method names and they
* always get to the documentation. If we don't do that, users need to
* cmd-click the method and then manually find the correct interface that
* contains the documentation.
* This is done for convenience: users can cmd-click method names and immediately
* see the documentation. If we don't do that, users need to cmd-click the method
* and then manually find the correct interface that contains the documentation.
*
* Hovering over a method/property works even without this script, but not all
* people are happy reading docs from the small hovering window.
*/

const fs = require('fs')
Expand Down Expand Up @@ -148,7 +150,7 @@ function parseImplements(line) {

// Strip generics. We need to do this in a loop to strip nested generics.
while (line.includes('<')) {
let strippedLine = line.replaceAll(GENERIC_ARGUMENTS_REGEX, '')
let strippedLine = line.replace(GENERIC_ARGUMENTS_REGEX, '')

if (strippedLine === line) {
console.warn(`unable to strip generics from "${line}"`)
Expand Down
5 changes: 3 additions & 2 deletions scripts/post-process-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const ASSET_PATH = path.join(__dirname, '..', 'assets')

// Files to go through and replace ASSET_URL_BASE with FIXED_ASSET_URL_BASE.
const ASSET_FIX_FILES = [path.join(DOCS_PATH, 'index.html')]
const ASSET_URL_BASE = 'https://github.com/koskimas/kysely/blob/master/assets'
const ASSET_URL_BASE =
/https:\/\/github.com\/koskimas\/kysely\/blob\/master\/assets/g
const FIXED_ASSET_URL_BASE = 'assets'

// Copy all assets to doc assets.
Expand All @@ -24,7 +25,7 @@ for (const filePath of ASSET_FIX_FILES) {
const file = fs
.readFileSync(filePath)
.toString()
.replaceAll(ASSET_URL_BASE, FIXED_ASSET_URL_BASE)
.replace(ASSET_URL_BASE, FIXED_ASSET_URL_BASE)

fs.writeFileSync(filePath, file)
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export * from './operation-node/column-definition-node.js'
export * from './operation-node/column-node.js'
export * from './operation-node/column-update-node.js'
export * from './operation-node/common-table-expression-node.js'
export * from './operation-node/common-table-expression-name-node.js'
export * from './operation-node/constraint-node.js'
export * from './operation-node/create-index-node.js'
export * from './operation-node/create-schema-node.js'
Expand Down
41 changes: 41 additions & 0 deletions src/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,41 @@ export class Kysely<DB> extends QueryCreator<DB> {
})
}

/**
* Returns a copy of this Kysely instance with tables added to its
* database type.
*
* This method only modifies the types and doesn't affect any of the
* executed queries in any way.
*
* ### Examples
*
* The following example adds and uses a temporary table:
*
* @example
* ```ts
* await db.schema
* .createTable('temp_table')
* .temporary()
* .addColumn('some_column', 'integer')
* .execute()
*
* const tempDb = db.withTables<{
* temp_table: {
* some_column: number
* }
* }>()
*
* await tempDb
* .insertInto('temp_table')
* .values({ some_column: 100 })
* .execute()
* ```
*/
withTables<T extends Record<string, Record<string, any>>>(): Kysely<DB & T> {
return new Kysely({ ...this.#props })
}

/**
* Releases all resources and disconnects from the database.
*
Expand Down Expand Up @@ -362,6 +397,12 @@ export class Transaction<DB> extends Kysely<DB> {
executor: this.#props.executor.withoutPlugins(),
})
}

override withTables<
T extends Record<string, Record<string, any>>
>(): Transaction<DB & T> {
return new Transaction({ ...this.#props })
}
}

export interface KyselyProps {
Expand Down
Loading

0 comments on commit e8b3120

Please sign in to comment.