Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm"
directory: "/" # Location of package.json
- package-ecosystem: 'npm'
directory: '/' # Location of package.json
schedule:
interval: "weekly"
interval: 'weekly'
groups:
all-dependencies:
patterns:
- '*'
# Always increase the version requirement
# to match the new version.
versioning-strategy: increase
29 changes: 17 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
push:
workflow_dispatch:

concurrency:
group: all
cancel-in-progress: true

env:
DATABASE_URL: ${{ secrets.CHINOOK_DATABASE_URL }}

Expand Down Expand Up @@ -81,7 +85,7 @@ jobs:
node_test=$(curl localhost:3000)
if [[ $node_test == *"{\"tracks\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ node with-javascript-express test passed"
npx kill-port 3000
npx kill-port 3000 -y
exit 0
fi
echo "❌ node with-javascript-express test failed"
Expand All @@ -98,7 +102,7 @@ jobs:
bun_test=$(curl localhost:3000)
if [[ $bun_test == *"{\"tracks\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ bun with-javascript-express test passed"
npx kill-port 3000
npx kill-port 3000 -y
exit 0
fi
echo "❌ bun with-javascript-express test failed"
Expand All @@ -112,7 +116,7 @@ jobs:
deno_test=$(curl localhost:3000)
if [[ $deno_test == *"{\"tracks\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ deno with-javascript-express test passed"
npx kill-port 3000
npx kill-port 3000 -y
exit 0
fi
echo "❌ deno with-javascript-express test failed"
Expand Down Expand Up @@ -224,14 +228,14 @@ jobs:
working-directory: examples/with-typescript-nextjs
run: |
npm i
npm run dev &
npx next dev -p 3005 &
sleep 3
node_test=$(curl localhost:3003)
node_test2=$(curl localhost:3003/api/hello)
node_test=$(curl localhost:3005)
node_test2=$(curl localhost:3005/api/hello)

if [[ $node_test == *"next.js json route"* && $node_test2 == *"{\"data\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ node with-typescript-nextjs test passed"
npx kill-port 3003
npx kill-port 3005 -y
exit 0
fi
echo "❌ node with-typescript-nextjs test failed"
Expand All @@ -243,13 +247,13 @@ jobs:
if [ "$RUNNER_OS" != "Windows" ]; then
bun i #re-installing dependencies in windows with bash causes a panic
fi
bun run dev &
bun next dev -p 3004 &
sleep 3
bun_test=$(curl localhost:3003)
bun_test2=$(curl localhost:3003/api/hello)
bun_test=$(curl localhost:3004)
bun_test2=$(curl localhost:3004/api/hello)
if [[ $bun_test == *"next.js json route"* && $bun_test2 == *"{\"data\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ bun with-typescript-nextjs test passed"
npx kill-port 3003
npx kill-port 3004 -y
exit 0
fi
echo "❌ bun with-typescript-nextjs test failed"
Expand All @@ -264,13 +268,14 @@ jobs:
deno_test=$(curl localhost:3003/api/hello)
if [[ $deno_test == *"{\"data\":[{\"TrackId\":1,\"Name\":\"For Those About To Rock (We Salute You)\",\"AlbumId\":1,\"MediaTypeId\":1,\"GenreId\":1,\"Composer\":\"Angus Young, Malcolm Young, Brian Johnson\",\"Milliseconds\":343719,\"Bytes\":11170334,\"UnitPrice\":0.99},{"* ]]; then
echo "✅ deno with-typescript-nextjs test passed"
npx kill-port 3003
npx kill-port 3003 -y
exit 0
fi
echo "❌ deno with-typescript-nextjs test failed"
exit 1

- name: remove with-typescript-nextjs
if: matrix.os != 'ubuntu-latest' #rm: cannot remove examples/with-typescript-nextjs: Directory not empty
run: rm -rf examples/with-typescript-nextjs

- name: node with-javascript-vite
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let database = new Database('sqlitecloud://user:password@xxx.sqlite.cloud:8860/c

let name = 'Breaking The Rules'

let results = await database.sql`SELECT * FROM tracks WHERE name = ${name}`
let results = await database.sql('SELECT * FROM tracks WHERE name = ?', name)
// => returns [{ AlbumId: 1, Name: 'Breaking The Rules', Composer: 'Angus Young... }]
```

Expand Down Expand Up @@ -82,7 +82,7 @@ await pubSub.listen(PUBSUB_ENTITY_TYPE.TABLE, 'albums', (error, results, data) =
}
})

await database.sql`INSERT INTO albums (Title, ArtistId) values ('Brand new song', 1)`
await database.sql("INSERT INTO albums (Title, ArtistId) values ('Brand new song', 1)")

// Stop listening changes on the table
await pubSub.unlisten(PUBSUB_ENTITY_TYPE.TABLE, 'albums')
Expand Down
2 changes: 1 addition & 1 deletion examples/with-javascript-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2 class="pb-4">Results:</h2>
var database = null;

sendButton.addEventListener('click', () => {
if (!database) {
if (!database || !database.isConnected()) {
// Get the input element by ID
var connectionStringinputElement = document.getElementById('connectionStringInput');
var connectionstring = connectionStringinputElement.value;
Expand Down
4 changes: 2 additions & 2 deletions examples/with-javascript-expo/components/AddTaskModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import { View, StyleSheet, Alert, Platform } from "react-native";
import { TextInput, Button, Modal } from "react-native-paper";
import DropdownMenu from "./DropdownMenu";
import db from "../db/dbConnection";
import getDbConnection from "../db/dbConnection";

export default AddTaskModal = ({
modalVisible,
Expand Down Expand Up @@ -30,7 +30,7 @@ export default AddTaskModal = ({

const getTags = async () => {
try {
const tags = await db.sql("SELECT * FROM tags");
const tags = await getDbConnection().sql("SELECT * FROM tags");
setTagsList(tags);
} catch (error) {
console.error("Error getting tags", error);
Expand Down
12 changes: 11 additions & 1 deletion examples/with-javascript-expo/db/dbConnection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { DATABASE_URL } from "@env";
import { Database } from "@sqlitecloud/drivers";

export default db = new Database(DATABASE_URL);
/**
* @type {Database}
*/
let database = null;

export default function getDbConnection() {
if (!database || !database.isConnected()) {
database = new Database(DATABASE_URL);
}
return database;
}
16 changes: 8 additions & 8 deletions examples/with-javascript-expo/hooks/useCategories.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useState, useEffect } from "react";
import db from "../db/dbConnection";
import getDbConnection from "../db/dbConnection";

const useCategories = () => {
const [moreCategories, setMoreCategories] = useState(["Work", "Personal"]);

const getCategories = async () => {
try {
const tags = await db.sql("SELECT * FROM tags");
const tags = await getDbConnection().sql("SELECT * FROM tags");
const filteredTags = tags.filter((tag) => {
return tag["name"] !== "Work" && tag["name"] !== "Personal";
});
Expand All @@ -21,7 +21,7 @@ const useCategories = () => {

const addCategory = async (newCategory) => {
try {
await db.sql(
await getDbConnection().sql(
"INSERT INTO tags (name) VALUES (?) RETURNING *",
newCategory
);
Expand All @@ -33,15 +33,15 @@ const useCategories = () => {

const initializeTables = async () => {
try {
const createTasksTable = await db.sql(
const createTasksTable = await getDbConnection().sql(
"CREATE TABLE IF NOT EXISTS tasks (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, isCompleted INT NOT NULL);"
);

const createTagsTable = await db.sql(
const createTagsTable = await getDbConnection().sql(
"CREATE TABLE IF NOT EXISTS tags (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, UNIQUE(name));"
);

const createTagsTasksTable = await db.sql(
const createTagsTasksTable = await getDbConnection().sql(
"CREATE TABLE IF NOT EXISTS tasks_tags (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, task_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, FOREIGN KEY (task_id) REFERENCES tasks(id), FOREIGN KEY (tag_id) REFERENCES tags(id));"
);

Expand All @@ -52,8 +52,8 @@ const useCategories = () => {
) {
console.log("Successfully created tables");

await db.sql("INSERT OR IGNORE INTO tags (name) VALUES (?)", "Work");
await db.sql(
await getDbConnection().sql("INSERT OR IGNORE INTO tags (name) VALUES (?)", "Work");
await getDbConnection().sql(
"INSERT OR IGNORE INTO tags (name) VALUES (?)",
"Personal"
);
Expand Down
20 changes: 10 additions & 10 deletions examples/with-javascript-expo/hooks/useTasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect, useCallback } from "react";
import db from "../db/dbConnection";
import getDbConnection from "../db/dbConnection";

const useTasks = (tag = null) => {
const [taskList, setTaskList] = useState([]);
Expand All @@ -8,7 +8,7 @@ const useTasks = (tag = null) => {
try {
let result;
if (tag) {
result = await db.sql(
result = await getDbConnection().sql(
`
SELECT tasks.*, tags.id AS tag_id, tags.name AS tag_name
FROM tasks
Expand All @@ -19,11 +19,11 @@ const useTasks = (tag = null) => {
);
setTaskList(result);
} else {
result = await db.sql`
result = await getDbConnection().sql(`
SELECT tasks.*, tags.id AS tag_id, tags.name AS tag_name
FROM tasks
JOIN tasks_tags ON tasks.id = tasks_tags.task_id
JOIN tags ON tags.id = tasks_tags.tag_id`;
JOIN tags ON tags.id = tasks_tags.tag_id`);
setTaskList(result);
}
} catch (error) {
Expand All @@ -33,7 +33,7 @@ const useTasks = (tag = null) => {

const updateTask = async (completedStatus, taskId) => {
try {
await db.sql(
await getDbConnection().sql(
"UPDATE tasks SET isCompleted=? WHERE id=? RETURNING *",
completedStatus,
taskId
Expand All @@ -47,21 +47,21 @@ const useTasks = (tag = null) => {
const addTaskTag = async (newTask, tag) => {
try {
if (tag.id) {
const addNewTask = await db.sql(
const addNewTask = await getDbConnection().sql(
"INSERT INTO tasks (title, isCompleted) VALUES (?, ?) RETURNING *",
newTask.title,
newTask.isCompleted
);
addNewTask[0].tag_id = tag.id;
addNewTask[0].tag_name = tag.name;
setTaskList([...taskList, addNewTask[0]]);
await db.sql(
await getDbConnection().sql(
"INSERT INTO tasks_tags (task_id, tag_id) VALUES (?, ?)",
addNewTask[0].id,
tag.id
);
} else {
const addNewTaskNoTag = await db.sql(
const addNewTaskNoTag = await getDbConnection().sql(
"INSERT INTO tasks (title, isCompleted) VALUES (?, ?) RETURNING *",
newTask.title,
newTask.isCompleted
Expand All @@ -75,8 +75,8 @@ const useTasks = (tag = null) => {

const deleteTask = async (taskId) => {
try {
await db.sql("DELETE FROM tasks_tags WHERE task_id=?", taskId);
const result = await db.sql("DELETE FROM tasks WHERE id=?", taskId);
await getDbConnection().sql("DELETE FROM tasks_tags WHERE task_id=?", taskId);
const result = await getDbConnection().sql("DELETE FROM tasks WHERE id=?", taskId);
console.log(`Deleted ${result.totalChanges} task`);
getTasks();
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-javascript-express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use(express.json())
/* http://localhost:3001/ returns chinook tracks as json */
app.get('/', async function (req, res, next) {
var database = new sqlitecloud.Database(DATABASE_URL)
var tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
var tracks = await database.sql('USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;')
res.send({ tracks })
})

Expand Down
15 changes: 12 additions & 3 deletions examples/with-javascript-vite/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { useEffect, useState } from "react";
import { Database } from "@sqlitecloud/drivers";

const db = new Database(import.meta.env.VITE_DATABASE_URL);
let db = null

function getDatabase() {
if (!db || !db.isConnected()) {
db = new Database(import.meta.env.VITE_DATABASE_URL);
}

return db;
}


function App() {
const [data, setData] = useState([]);

const getAlbums = async () => {
const result = await db.sql`
const result = await getDatabase().sql(`
USE DATABASE chinook.sqlite;
SELECT albums.AlbumId as id, albums.Title as title, artists.name as artist
FROM albums
INNER JOIN artists
WHERE artists.ArtistId = albums.ArtistId
LIMIT 20;
`;
`);
setData(result);
};

Expand Down
2 changes: 1 addition & 1 deletion examples/with-plain-javascript/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function selectTracks() {
var database = new sqlitecloud.Database(DATABASE_URL)

// run async query
var tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
var tracks = await database.sql('USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;')
console.log(`selectTracks returned:`, tracks)

// You can also use all the regular sqlite3 api with callbacks, see:
Expand Down
2 changes: 1 addition & 1 deletion examples/with-typescript-nextjs/app/api/hello/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function GET(request: NextRequest) {
const database = new Database(DATABASE_URL)

// retrieve rows from chinook database using a plain SQL query
const tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
const tracks = await database.sql('USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;')

// return as json response
return NextResponse.json<{ data: any }>({ data: tracks })
Expand Down
1 change: 0 additions & 1 deletion examples/with-typescript-nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Image from 'next/image'
import styles from './page.module.css'

export default function Home() {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-typescript-react-native/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function App() {
const db = new Database(`${DATABASE_URL}`);

const result =
await db.sql`USE DATABASE chinook.sqlite; SELECT albums.AlbumId as id, albums.Title as title, artists.name as artist FROM albums INNER JOIN artists WHERE artists.ArtistId = albums.ArtistId LIMIT 20;`;
await db.sql('USE DATABASE chinook.sqlite; SELECT albums.AlbumId as id, albums.Title as title, artists.name as artist FROM albums INNER JOIN artists WHERE artists.ArtistId = albums.ArtistId LIMIT 20;');

setAlbums(result);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sqlitecloud/drivers",
"version": "1.0.417",
"version": "1.0.422",
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
Loading
Loading