Welcome to Github-Gist-DB 👋
Unlimited GitHub Gist DB is a lightweight NoSQL database package for Node.js, designed to store JSON data in GitHub Gists, providing CRUD operations and more.
Because it depends on the gists and Github says that you can create an unlimted gists and unlimited requests 🤑 for free.
Table of Contents
Install
npm install github-gist-db
Create Method
import { DB } from "github-gist-db";
interface Product {
name: string;
price: number;
}
const productSchema = new DB<Product>(
{
name: "String",
price: "Number",
},
{
githubToken: process.env.GITHUB_ACCESS_TOKEN!,
schemaName: "productSchema",
projectName: "test",
gistId: "48ec463b54be5973729a108297860555",
timeStamps: true,
}
);
(async () => {
const product = await productSchema.create({
name: "laptop lenovo",
price: 500,
});
console.log(product);
const updatedProduct = await productSchema.findOneAndUpdate(
{ name: "iphone 15 pro max" },
{ name: "laptop Dell", price: 800 }
);
console.log(updatedProduct);
const deletionStatus = await productSchema.findByIdAndDelete(
"33a66454-fc9a-4016-bc01-45731fc16be3"
);
console.log(deletionStatus);
})();
Learn
First you have to define the Schema (the body of your database)
import { DB } from "github-gist-db";
interface Product {
name: string;
price: number;
}
const productSchema = new DB<Product>(
{
name: "String",
price: "Number",
},
{
githubToken: process.env.GITHUB_ACCESS_TOKEN!,
schemaName: "productSchema",
projectName: "test",
gistId: "48ec463b54be5973729a108297860555",
timeStamps: true,
}
);
1`
{
name: "String",
price: "Number",
},
this is the fields and its types of your database
you can define many fields as you want.
And here is the types you can create with
| "String"
| "Number"
| "Boolean"
| "Object"
| "Array"
| "Undefined"
| "Null"
| "Symbol"
| "BigInt"
`;
githubToken: process.env.GITHUB_ACCESS_TOKEN!. your github access token you can create it in you Developer Settings

Only Check Gist

And then click Generate Token

This is your github Token

timeStamps: true 3. timeStamps: true, will add CreatedAt and updatedAT in your schema. whenever you create a new Document Example (new product)
Example createdAt: '2024-03-04T12:35:52.641Z', updatedAt: '2024-03-04T12:35:52.643Z'
Create Method
const product = await productSchema.create({
name: "laptop lenovo",
price: 500,
});
console.log(product);
FindMany Method
console.log(await productSchema.findMany());
findFirst Method
console.log(await productSchema.findMany());
findByIdAndUpdate Method
console.log(
await productSchema.findByIdAndUpdate(
"29ad41de-b015-4d96-a9d4-1a5c5a4a4ec7",
{ name: "laptop Dell", price: 800 }
)
);
findOneAndUpdate Method
console.log(
await productSchema.findByIdAndUpdate(
"29ad41de-b015-4d96-a9d4-1a5c5a4a4ec7",
{ name: "laptop Dell", price: 800 }
)
);
findByIdAndDelete Method
console.log(
await productSchema.findByIdAndUpdate(
"29ad41de-b015-4d96-a9d4-1a5c5a4a4ec7",
{ name: "laptop Dell", price: 800 }
)
);
findOneAndDelete Method
console.log(
await productSchema.findOneAndDelete({id:"479a474b-a668-4407-8543-adcae24d9f91"})
);
Author
👤 ElTahawy
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2024 Amer Eltahawy.
This project is MIT licensed.