Skip to content

Commit 0cf4a14

Browse files
init :-)
1 parent 41f86fe commit 0cf4a14

5 files changed

Lines changed: 136 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
# github-db
1+
# A key value store using Github.
2+
3+
## Usage
4+
5+
```
6+
const GithubDb=require("github-db");
7+
8+
const db= GithubDb({db:"test-db",token:"test"});
9+
(async function(){
10+
try {
11+
const id=await db.add("user",{name:"John"});
12+
console.log("added user", id);
13+
14+
const id2=await db.add("user",{name:"Will"});
15+
console.log("added user", id2);
16+
17+
const user=await db.fetchOne("user",id);
18+
console.log("fetched user", user);
19+
const users=await db.fetchAll("user");
20+
console.log("fetched users", users);
21+
} catch (error) {
22+
console.error(error);
23+
}
24+
})()
25+
```
26+

index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const axios= require("axios");
2+
3+
const url= `https://github-db.glitch.me/db/api`;
4+
5+
function Client({db,token}){
6+
const options={db,token};
7+
let validated=false;
8+
async function validate(){
9+
if(!validated){
10+
const {data}=await axios.get(`${url}/validate`,{params:options});
11+
validated=data.valid
12+
}
13+
}
14+
async function add(document,payload){
15+
await validate();
16+
const resp=await axios.post(`${url}/add`,{db:options.db,token,document,payload});
17+
return resp.data.identifier;
18+
}
19+
async function fetchOne(document,identifier){
20+
await validate();
21+
const resp=await axios.get(`${url}/fetchOne`,{params:{db:options.db,token,document,identifier}});
22+
return resp.data;
23+
}
24+
async function fetchAll(document){
25+
await validate();
26+
const resp=await axios.get(`${url}/fetchAll`,{params:{db:options.db,token,document}});
27+
return resp.data;
28+
}
29+
return {
30+
add,fetchOne,fetchAll
31+
}
32+
}
33+
module.exports= Client;

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "github-db",
3+
"version": "1.0.0",
4+
"description": "a key value database ",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/kuldeepkeshwar/github-db.git"
12+
},
13+
"author": "kuldeepkeshwar",
14+
"license": "MIT",
15+
"bugs": {
16+
"url": "https://github.com/kuldeepkeshwar/github-db/issues"
17+
},
18+
"homepage": "https://github.com/kuldeepkeshwar/github-db#readme",
19+
"dependencies": {
20+
"axios": "^0.19.0"
21+
}
22+
}

test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
const GithubDb=require("github-db");
3+
4+
const db= GithubDb({db:"test-db",token:"test"});
5+
(async function(){
6+
try {
7+
const id=await db.add("user",{name:"John"});
8+
console.log("added user", id);
9+
10+
const id2=await db.add("user",{name:"Will"});
11+
console.log("added user", id2);
12+
13+
const user=await db.fetchOne("user",id);
14+
console.log("fetched user", user);
15+
const users=await db.fetchAll("user");
16+
console.log("fetched users", users);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
})()

yarn.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
axios@^0.19.0:
6+
version "0.19.0"
7+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
8+
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
9+
dependencies:
10+
follow-redirects "1.5.10"
11+
is-buffer "^2.0.2"
12+
13+
debug@=3.1.0:
14+
version "3.1.0"
15+
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
16+
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
17+
dependencies:
18+
ms "2.0.0"
19+
20+
21+
version "1.5.10"
22+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
23+
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
24+
dependencies:
25+
debug "=3.1.0"
26+
27+
is-buffer@^2.0.2:
28+
version "2.0.3"
29+
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
30+
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==
31+
32+
33+
version "2.0.0"
34+
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
35+
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

0 commit comments

Comments
 (0)