smart-database
v1.2.1
Published
This is smart database using firebase . it is only for those students whose learn forntend . they can use firebase as a backend to save own data .
Downloads
7
Maintainers
Readme
Basic setting
[!NOTE] smart-database only usable with vite projects make sure you create vite project
to create vite priject like this
** install vite **
npm create vite@latest
Step : 1
** create .env file in your root directory of vite project ** **add all values from your firebase project
VITE_API_KEY = "..."
VITE_AUTH_DOMAIN = "..."
VITE_PROJECT_ID = "..."
VITE_STORAGE_BUCKET = "..."
VITE_MESSAGING_SENDER_ID = "..."
VITE_APP_ID = "..."
** Enable firestore , auth, Oauth and storage whatever you want from your firebase projects
Quick start
npm i smart-database
** upload doc on your firebase
import { services } from "smart-database";
let data = {
name: "Prince nishad",
email: "[email protected]",
age: 18,
phone: "0000000",
};
function uploadData() {
services
.uploadDoc("users", "123", data) // required 3 paramater collectionName, id, data
.then((res) => {
console.log(res); // here is response from firebase
})
.catch((err) => {
console.log(err); // here is error
});
}
Get single data
function getOneDoc() {
services
.getOneDoc("user", "444") // required 2 parameter : collection name, id
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err.code);
});
}
update docs in collection users
function updateData() {
services
.updateDoc("users", "123", data) // it's take 3 parameter : collectionName, id, data- whatever you want to change
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}
Delete doc by id
function deleteData() {
services
.deleteDoc("user", "777") required parameter : CollectionName, id
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}
get all docs from your firebase
function getAllDocs() {
services
.getAllDocs("user") // required 1 parameter : collection name
.then((res) => {
console.log(res); // here is all data
})
.catch((err) => {
console.log(err.code);
});
}
search data in your firebase database
function searchData() {
services
.searchDocs("user", "username", "prince123") // required 3 paranters : collection name, key, value
.then((res) => {
console.log(res);
})
.catch((err) => {
console(err);
});
}
get limit data in your firebase database
function limitData() {
services
.getLimitDocs("user", "phone", 8) // required 3 parameters: collectionName, key, length
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}