1.3.2 • Published 6 months ago

cloudflare-d1-http-knex v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

cloudflare-d1-http-knex

License: MIT NPM Version Coverage Status Testing Status

An npm package that query Cloudflare's D1 through Query D1 Database API and Knex.

Installation

npm install cloudflare-d1-http-knex

# or
bun add cloudflare-d1-http-knex

Usage

import { createConnection } from 'cloudflare-d1-http-knex';

// The connection function returns a Knex instance
const connection = createConnection({
  account_id: 'account_id',
  database_id: 'database_id',
  key: 'key',
});

const query = await connection('table_name').select('*');

Mocking

  1. Install better-sqlite3: npm install -D better-sqlite3.
  2. Using in case:
import { createConnection } from 'cloudflare-d1-http-knex'
import { mockedFetch } from 'cloudflare-d1-http-knex/mock'

const db = createConnection({
  account_id: 'xxxx',
  database_id: 'xxxx',
  key: 'xxxx',
  mockedFetch, // Using mocked fetch, it won't connect to real D1 database.
})

await db.raw('SELECT 1+1')

Usage mockedFetch as Global in Jest

You should add below codes to your jest setup files.

import { mockedFetch } from 'cloudflare-d1-http-knex/mock'

global.fetch = jest.fn(mockedFetch)

Changelog

See CHANGELOG.md.

1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago