All Projects → cloudflare → Db Connect

cloudflare / Db Connect

Licence: mit
🚀 Connect your SQL database to Cloudflare Workers

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Db Connect

Go Postgres Jwt React Starter
A go, gin, and postgres API with jwt auth, complete with a react frontend
Stars: ✭ 115 (-10.16%)
Mutual labels:  sql
Specql
Automatic PostgreSQL CRUD queries
Stars: ✭ 120 (-6.25%)
Mutual labels:  sql
Timescaledb
An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
Stars: ✭ 12,211 (+9439.84%)
Mutual labels:  sql
Sqlite3 To Mysql
Make an Sqlite3 export MySQL readable.
Stars: ✭ 116 (-9.37%)
Mutual labels:  sql
Rbql
🦜RBQL - Rainbow Query Language: SQL-like language for (not only) CSV file processing. Supports SQL queries with Python and JavaScript expressions
Stars: ✭ 118 (-7.81%)
Mutual labels:  sql
Sergeant
💂 Tools to Transform and Query Data with 'Apache' 'Drill'
Stars: ✭ 120 (-6.25%)
Mutual labels:  sql
Sql Kit
*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Stars: ✭ 115 (-10.16%)
Mutual labels:  sql
Projac
A set of .NET projection libraries
Stars: ✭ 126 (-1.56%)
Mutual labels:  sql
Mysql Container
MySQL container images based on Red Hat Software Collections and intended for OpenShift and general usage. Users can choose between Red Hat Enterprise Linux, Fedora, and CentOS based images.
Stars: ✭ 117 (-8.59%)
Mutual labels:  sql
Vs Deploy
Visual Studio Code extension that provides commands to deploy files of a workspace to a destination.
Stars: ✭ 123 (-3.91%)
Mutual labels:  sql
Sqlkit
SQL builder and powerful database toolkit for Golang
Stars: ✭ 117 (-8.59%)
Mutual labels:  sql
Cs notes
🚀自我小结
Stars: ✭ 118 (-7.81%)
Mutual labels:  sql
Rocket Api
API敏捷开发框架,用于API接口功能的快速开发。不再定义Controller,Service,Dao,Mybatis,xml,Entity,VO等对象和方法.以springboot starter 形式集成使用
Stars: ✭ 122 (-4.69%)
Mutual labels:  sql
Slick Migration Api
Schema manipulation dialects and DSL for Slick (mirrored from gitlab)
Stars: ✭ 116 (-9.37%)
Mutual labels:  sql
Pulsar Flink
Elastic data processing with Apache Pulsar and Apache Flink
Stars: ✭ 126 (-1.56%)
Mutual labels:  sql
Slack Sql
🎉 Bring SQL console to Slack
Stars: ✭ 115 (-10.16%)
Mutual labels:  sql
Vanillacore
The core engine of VanillaDB
Stars: ✭ 119 (-7.03%)
Mutual labels:  sql
Elasticsearch Sql
parse sql into elasticsearch dsl with antlr4
Stars: ✭ 127 (-0.78%)
Mutual labels:  sql
Activerecord where assoc
Make ActiveRecord do conditions on your associations
Stars: ✭ 126 (-1.56%)
Mutual labels:  sql
Gsheets Db Api
A Python DB-API and SQLAlchemy dialect to Google Spreasheets
Stars: ✭ 122 (-4.69%)
Mutual labels:  sql

db-connect

⚠️ This was an experimental project and is not supported.

Connect your SQL database to Cloudflare Workers. Import this lightweight Javascript library to execute commands or cache queries from a database through an Argo Tunnel. Although designed for Workers, this library can be used in any environment that has access to the Fetch and SubtleCrypto APIs.

Installation

npm i -s @cloudflare/db-connect

Example

import { DbConnect } from '@cloudflare/db-connect'

const db = new DbConnect({
  host: 'sql.mysite.com', // Hostname of an Argo Tunnel
  clientId: 'xxx', // Client ID of an Access service token
  clientSecret: 'xxx' // Client Secret of an Access service token
})

async function findBirthday(name) {
  const resp = await db.submit({
    statement: 'SELECT * FROM users WHERE name = ? LIMIT 1',
    arguments: [ name ],
    cacheTtl: 60
  })

  if(!resp.ok) {
    return new Error('oops! could not find user.')
  }

  const users = await resp.json()
  // [ { "id": 1111,
  //   "name": "Matthew",
  //   "birthday": "2009-07-01" } ]

  return users[0].birthday
}

findBirthday('Matthew').then(bday => console.log(bday))

Quickstart

db-connect requires that you setup Cloudflare Access, Argo Tunnel, and Workers. You can use the quickstart command below or read the quickstart file for details on how to set this up yourself.

npm i -g @cloudflare/db-connect
db-connect-quickstart

Databases

db-connect supports the following database drivers out-of-the-box. If your database is not explicitly on the list it may still be supported. For instance, MariaDB uses the MySQL protocol and CockroachDB uses the PostgreSQL protocol.

Documentation

new DbConnect(options)

import { DbConnect } from '@cloudflare/db-connect'

const db = new DbConnect({
  host,         // required, hostname of your Argo Tunnel running in db-connect mode.
  clientId,     // recommended, client id from your Access service token.
  clientSecret, // recommended, client secret from your Access service token.
})

Promise<Response> db.ping()

import { DbConnect } from '@cloudflare/db-connect'

const db = new DbConnect({...})

async function myPing() {
  const resp = await db.ping()
  if(resp.ok) {
    return true
  }
  throw new Error(await resp.text())
}

new Command(options)

import { Command } from '@cloudflare/db-connect'

const cmd = new Command({
  statement, // required, the database statement to submit.
  arguments, // optional, either an array or object of arguments.
  mode,      // optional, type of command as either 'query' or 'exec'.
  isolation, // optional, type of transaction isolation, defaults to 'none' for no transactions.
  timeout,   // optional, number of seconds before a timeout, defaults to infinite.
  cacheTtl,  // optional, number of seconds to cache responses, defaults to -1.
  staleTtl,  // optional, after cacheTtl expires, number of seconds to serve stale, defaults to -1.
})

Promise<Response> db.submit(command)

import { DbConnect, Command } from '@cloudflare/db-connect'

const db = new DbConnect({...})

const cmd = new Command({
  statement: 'SELECT COUNT(*) AS n FROM books',
  cacheTtl: 60
})

async function mySubmit() {
  const resp = await db.submit(cmd)
  if(resp.ok) {
    return await resp.json() // [ { "n": 1234 } ]
  }
  throw new Error(await resp.text())
}

Testing

If you want to test db-connect without a database you can use the following command to create an in-memory SQLite3 database:

cloudflared db-connect --playground
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].