Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase 🔥add new project #44

Open
adhilsalim opened this issue May 8, 2023 · 1 comment
Open

firebase 🔥add new project #44

adhilsalim opened this issue May 8, 2023 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation low priority This issue is not critical and can be addressed at a later time

Comments

@adhilsalim
Copy link
Member

@AkhilLV try this function, we can use push() method to generate a unique key from firebase.

We have to think about the structure as well (here is what's in my mind):

users
|____name
|____bio 
.....
|_____projects
             |_______NdlAi75rFlnDAhjaiGSjamqUVvhsBM
                                                 |_______________________name
                                                 |_______________________description

just like we had user-usernames node we need to create one more something like: users-projects.
There is something called, multi-path update and batch write (which i really dk) for updating more than one node, this ensures that either all nodes update successfully otherwise all fails (data consistency).

The following is a sample function to add project to the path /projects (projects is a parent node in this example)

// function add project
const addProject = (name, project_id, description) => {
// setting reference to the project node 
  const projectsRef = ref(database, "projects");
// getting reference to the project (which includes unique id) created by firebase using push()
  const newProjectRef = push(projectsRef);
// getting unique key
  const projectId = newProjectRef.key;

  const project = {
    name,
    project_id,
    description
  };

  set(newProjectRef, project)
    .then(() => {
      // success .....
    })
    .catch((error) => {
      // error .....
    });
};

@adhilsalim adhilsalim added documentation Improvements or additions to documentation low priority This issue is not critical and can be addressed at a later time labels May 8, 2023
@adhilsalim
Copy link
Member Author

adhilsalim commented May 8, 2023

@adhilsalim adhilsalim pinned this issue May 8, 2023
@adhilsalim adhilsalim assigned adhilsalim and unassigned AkhilLV May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation low priority This issue is not critical and can be addressed at a later time
Projects
None yet
Development

No branches or pull requests

2 participants