-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrud.js
More file actions
62 lines (58 loc) · 2.26 KB
/
crud.js
File metadata and controls
62 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//const { table } = require("node:console");
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBQBrocDElLvzcUzhgj_0R0muUHKVjW_BM",
authDomain: "awt-lab.firebaseapp.com",
databaseURL: "https://awt-lab-default-rtdb.firebaseio.com",
projectId: "awt-lab",
storageBucket: "awt-lab.appspot.com",
messagingSenderId: "473715207538",
appId: "1:473715207538:web:2180d74279b6b9526c41eb",
measurementId: "G-TE2SCW0Y8Q"
};
firebase.initializeApp(firebaseConfig)
var dbRef=firebase.database().ref().child("students")
function createStudent(){
console.log("Create Student");
let uname=document.getElementById('uname').value;
let rno=document.getElementById('rno').value;
let bns=document.getElementById('bns').value;
dbRef.child(uname).set({
uname:uname,
rno:rno,
bns:bns
})
console.log("User Created Successfully");
}
function deleteStudent(){
console.log("Delete Student");
let username=window.prompt("Enter the name of the student to be deleted");
dbRef.child(username).remove();
console.log(username+" removed");
}
function displayStudent()
{
console.log("Student Details");
table=document.createElement("TABLE");
table.border="2";
dbRef.on('child_added',(snap)=>{
console.log(snap.key)
row=table.insertRow(-1)
cell1=row.insertCell(-1)
cell2=row.insertCell(-1)
cell3=row.insertCell(-1)
cell1.innerHTML=snap.val().uname;
cell2.innerHTML=snap.val().rno;
cell3.innerHTML=snap.val().bns;
})
student=document.getElementById("studentList");
student.appendChild(table)
}
function updateStudent(){
console.log("Update Student");
let uname=window.prompt("Enter username");
let rno=window.prompt("Enter rno");
let bns=window.prompt("Enter branch and section");
dbRef.child(uname).update({rno:rno,bns:bns});
console.log("Student Details Updated Successfully");
}