Skip to content

Commit

Permalink
Zero dependencies, not even runtime deps
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed May 11, 2022
1 parent 48c9934 commit 536c413
Show file tree
Hide file tree
Showing 23 changed files with 461 additions and 947 deletions.
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ All you need to do is define an interface for each table in the database and pas
interfaces to the `Kysely` constructor:

```ts
import { Pool } from 'pg'
import {
Kysely,
PostgresDialect,
Expand Down Expand Up @@ -125,9 +126,11 @@ interface Database {
const db = new Kysely<Database>({
// Use MysqlDialect for MySQL and SqliteDialect for SQLite.
dialect: new PostgresDialect({
host: 'localhost',
database: 'kysely_test',
}),
pool: new Pool({
host: 'localhost',
database: 'kysely_test'
})
})
})

async function demo() {
Expand Down Expand Up @@ -319,6 +322,9 @@ need to depend on a typescript compiler, which most production environments don'
have. You will probably want to add a simple migration script to your projects like this:

```ts
import * as path from 'path'
importPool } from 'pg'
import { promises: fs } from 'fs'
import {
Kysely,
Migrator,
Expand All @@ -329,17 +335,20 @@ import {
async function migrateToLatest() {
const db = new Kysely<Database>({
dialect: new PostgresDialect({
host: 'localhost',
database: 'kysely_test',
pool: new Pool({
host: 'localhost',
database: 'kysely_test',
})
}),
})

const migrator = new Migrator({
db,
provider: new FileMigrationProvider(
// Path to the folder that contains all your migrations.
'some/path/to/migrations'
)
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: 'some/path/to/migrations',
})
})

const { error, results } = await migrator.migrateToLatest()
Expand Down Expand Up @@ -376,17 +385,15 @@ Kysely doesn't include drivers for deno, but you can still use Kysely as a query
or implement your own driver:

```ts
// We use jsdeliver to get Kysely from npm. We also need to
// import the `dist/esm/index-nodeless.js` file instead of the
// root which has node dependencies.
// We use jsdeliver to get Kysely from npm.
import {
DummyDriver,
Generated,
Kysely,
PostgresAdapter,
PostgresIntrospector,
PostgresQueryCompiler,
} from 'https://cdn.jsdelivr.net/npm/kysely/dist/esm/index-nodeless.js'
} from 'https://cdn.jsdelivr.net/npm/kysely/dist/esm/index.js'

interface Person {
id: Generated<number>
Expand Down Expand Up @@ -425,9 +432,7 @@ console.log(sql.sql)

# Browser

Kysely also runs in the browser as long as you import the `dist/esm/index-nodeless.js`
module instead of the root that has node dependencies. You can also import the
`dist/cjs/index-nodeless.js` file if you are using commonjs modules instead of ESM.
Kysely also runs in the browser:

```ts
import {
Expand All @@ -437,7 +442,7 @@ import {
SqliteAdapter,
SqliteIntrospector,
SqliteQueryCompiler,
} from 'kysely/dist/esm/index-nodeless.js'
} from 'kysely'

interface Person {
id: Generated<number>
Expand Down
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kysely",
"version": "0.18.1",
"version": "0.19.0",
"description": "Type safe SQL query builder",
"repository": {
"type": "git",
Expand All @@ -15,9 +15,7 @@
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./dist/cjs/index-nodeless.js": "./dist/cjs/index-nodeless.js",
"./dist/esm/index-nodeless.js": "./dist/esm/index-nodeless.js"
}
},
"scripts": {
"clean": "rm -rf dist && rm -rf test/node/dist && rm -rf test/browser/bundle.js",
Expand All @@ -43,9 +41,6 @@
},
"author": "Sami Koskimäki <[email protected]>",
"license": "MIT",
"dependencies": {
"@types/node": "^16.11.9"
},
"devDependencies": {
"@types/better-sqlite3": "^7.5.0",
"@types/chai": "^4.3.1",
Expand Down
Loading

0 comments on commit 536c413

Please sign in to comment.