DocuLite lets you use SQLite like Firebase Firestore. It's written in Typescript and an adapter on top of sqlite3 and sqlite. It support listeners on documents, collections, and basic queries. Google Group for users to discuss issues, problems, feature requests: Google Group
This is early work, so please treat it appropriately.
Example:
import { Database } from "doculite";
// Creates sqlite.db file in the cwd
const db = new Database();
Collections are created on first insertion of a document. They are represented by a SQLite Table.
// create ref to the doc. Doc ID optional.
const usersRef = db.collection("users").doc("123");
const refWithoutId = db.collection("users").doc();
// Any valid Javascript object that can be parsed to valid JSON can be inserted as a document.
await usersRef.set({
username: "John Doe",
createdAt: "123",
updatedAt: "123",
});
await refWithoutId.set({ username: "Jane Doe" });
// define ref
const usersRef = db.collection("users").doc("123");
// get
const user = await usersRef.get();
// print
console.log(user); // prints { username: "John Doe" };
// ref
const usersRef = db.collection("users").doc("123");
// Properties existing on both old and new object will be updated.
// Properties only existing on the new object will be added.
// If merge is false, properties only present on the old object will be deleted.
// Merge is true by default
await ref.set({ username: "DERP Doe", updatedAt: "345" }, { merge: true });
// document in DB is now { username: "DERP Doe", updatedAt: "345", createdAt: "123" }
await ref.set({ username: "DERP Doe", updatedAt: "345" }, { merge: false });
// document in DB is now { username: "DERP Doe", updatedAt: "345" }
const db = new Database();
const ref = db.collection("users").doc("deletable");
await ref.set({ username: "deletableUsername", updatedAt: 123123 });
await ref.delete();
const doc = await ref.get();
console.log(doc); // prints null
// ref to doc
const ref = db.collection("users").doc("123");
// snapshot listener returns unsubscribe function
const unsub = ref.onSnapshot((doc) => {
console.log("Omg the user doc is updating!", doc?.username);
});
await ref.set({ username: "SHEESH Doe", updatedAt: 2 });
// prints: `Omg the user doc is updating! SHEESH Doe`
// unsub
unsub();
const usersRef = db.collection("users");
await usersRef.doc().set({ username: "Doculite", updatedAt: 234 });
const query = usersRef.where("username", "Doculite");
const docs = await query.get();
const user = docs[0];
console.log(user.username); // prints `Doculite`
- Better query-based system
- Stability and speed updates
- Delete collections
- Subcollections
- Listeners on queries / multiple documents
- Queries with other comparison operators (<, >, >=, <=, contains, etc.)
- Queries for multiple variables (without indexes, probably)
- Queries with Full Text Search (without indexes, probably)