Code Monkey home page Code Monkey logo

firebase4j's Introduction

๐Ÿ”ฅโ˜• firebase4j

A plugin Java for Firebase applications

๐Ÿ’ก Installing

Add the dependency in your pom.xml

<dependency>
  <groupId>com.renz</groupId>
  <artifactId>firebase4j</artifactId>
  <version>1.0.1</version>
</dependency>

Execute the command

mvn install

๐Ÿƒ Usage

Connect to Firebase before using services

try (FirebaseConnection firebaseConn = new FirebaseConnection()) {
			
  firebaseConn.connect("src/main/resources/YOUR_FIREBASE_ADMIN_SDK.json");

  // Code block using services
			
} catch (Exception e) {
  // exception handling
}

To use Firestore, first you must configure your classes that will be persisted in the Database

Inherit the "Document" class in your collection model

import com.renz.firebase4j.firestore.Document;

public class Person extends Document {

  private String name;
  private Integer age;

  // getter's and setter's
}

Create a repository that inherits from the "FirestoreRepository" class and give the constructor the type of document class you would like to handle

public class PersonRepository extends FirestoreRepository<Person> {

  public PersonRepository() {
    super(Person.class);
  }
  
}

Now invoke the available methods

try (FirebaseConnection firebaseConn = new FirebaseConnection()) {

  firebaseConn.connect("src/main/resources/YOUR_FIREBASE_ADMIN_SDK.json");

  PersonRepository personRep = new PersonRepository();

  Person person = personRep.save(person); // create document 

  List<Person> results = personRep.findAll(); // consulting collections

  personRep.delete(person.getId()); // search for a specific document by id 

} catch (Exception e) {
  // exception handling
}

Uploading files to Firebase Storage

try (FirebaseConnection firebaseConn = new FirebaseConnection()) {

  firebaseConn.connect("src/main/resources/YOUR_FIREBASE_ADMIN_SDK.json");

  FirebaseStorage storage = new FirebaseStorage();

  storage.uploadFile(new File("YOUR_FILE.extension"));

} catch (Exception e) {
  // exception handling
}

๐Ÿ’ป Want to help with the Project?

Create an "issue" and describe the features you would like in the application, or even bugs you found.

If you want to help with corrections, create your branch from master and open a Pull Request for me.

โญ Could you favorite this repository? Just click on the star! Thank you very much!

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.