Skip to content

Commit

Permalink
Merge pull request #60 from CRBroughton/46-add-support-for-libsql
Browse files Browse the repository at this point in the history
46 add support for libsql
  • Loading branch information
CRBroughton authored Apr 11, 2024
2 parents 5cd73ef + 95b7786 commit 611649e
Show file tree
Hide file tree
Showing 22 changed files with 1,690 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-eagles-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@crbroughton/sibyl": minor
---

Add libSQL support - Sibyl now supports the libSQL implementation of SQLite
2 changes: 2 additions & 0 deletions .github/workflows/vitest.yml → .github/workflows/bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
run: cd src/sqljs && bun install
- name: Install dependencies for Bun
run: cd src/bun && bun install
- name: Install dependencies for libSQL
run: cd src/libsql && bun install
- name: Run unit tests
run: bun test
- uses: actions/upload-artifact@v3
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sibyl

Sibyl is a lightweight SQLite query builder for <a href="https://github.com/sql-js/sql.js">SQL.js</a> and <a href="https://bun.sh/docs/api/sqlite">Bun's sqlite3 driver</a>, providing a Prisma-like query builder. Sibyl is in early development,
Sibyl is a lightweight SQLite query builder for <a href="https://github.com/sql-js/sql.js">libSQL</a>, <a href="https://bun.sh/docs/api/sqlite">Bun's sqlite3 driver</a>, and <a href="https://github.com/tursodatabase/libsql">libSQL</a>, providing a Prisma-like query builder. Sibyl is in early development,
so expect breaking changes and rapid development.

## Getting Started
Expand Down Expand Up @@ -29,11 +29,22 @@ Bun documentation</a>. The Bun implemenation of Sibyl can be installed
with the following command:

```bash
bun install @crbroughton/sibyl:bun
bun install @crbroughton/sibyl_bun
```
Sibyl will then accept the native Bun SQLite `Database`, again, see the <a href="https://bun.sh/docs/api/sqlite">
Bun documentation</a>.

#### libSQL Installation

The libSQL implemenation of Sibyl can be installed
with the following command:

```bash
bun install @crbroughton/sibyl_libsql libsql
```
Sibyl will then accept libSQL `Database`, then see the <a href="https://github.com/tursodatabase/libsql-js?tab=readme-ov-file#getting-started">
libSQL Getting Started Guide</a>.

#### Getting Started

To start off with Sibyl, you'll first have to ensure Sibyl is able to be run inside
Expand Down
175 changes: 175 additions & 0 deletions libsql-playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions libsql-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# libsql-playground

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.1.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added libsql-playground/bun.lockb
Binary file not shown.
86 changes: 86 additions & 0 deletions libsql-playground/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Sibyl from '@crbroughton/sibyl_libsql'
import Database from 'libsql'

const db = new Database(':memory:')

// Create table schema
interface Tables {
firstTable: {
id: number
name: string
location: string
hasReadTheReadme: boolean
}
}
const { createTable, Insert, Select, All } = await Sibyl<Tables>(db)

createTable('firstTable', {
id: {
autoincrement: true,
type: 'INTEGER',
primary: true,
unique: true,
},
name: {
type: 'char',
},
hasReadTheReadme: {
type: 'bool',
},
location: {
type: 'char',
},
})

Insert('firstTable', [
{
id: 1,
hasReadTheReadme: true,
location: 'Brighton',
name: 'Craig',
},
{
id: 2,
hasReadTheReadme: false,
location: 'Leeds',
name: 'Bob',
},
{
id: 3,
hasReadTheReadme: true,
location: 'Brighton',
name: 'David',
},
])

const allResponse = All('firstTable')
console.log(allResponse)

const selectedResponse = Select('firstTable', {
where: {
id: 1,
},
})
console.log(selectedResponse)

const selectedResponseWithMultiple = Select('firstTable', {
where: {
id: 1,
location: 'Brighton',
},
})
console.log(selectedResponseWithMultiple)

const selectedREsponseWithORStatement = Select('firstTable', {
where: {
OR: [
{
name: 'Craig',
},
{
hasReadTheReadme: 1,
},
],
},
})
console.log('here', selectedREsponseWithORStatement)
15 changes: 15 additions & 0 deletions libsql-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "libsql-playground",
"type": "module",
"module": "index.ts",
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@crbroughton/sibyl_libsql": "^2.1.2",
"libsql": "^0.3.11"
},
"devDependencies": {
"@types/bun": "latest"
}
}
27 changes: 27 additions & 0 deletions libsql-playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
Loading

0 comments on commit 611649e

Please sign in to comment.