Skip to content

Latest commit

 

History

History
118 lines (75 loc) · 2.51 KB

README.md

File metadata and controls

118 lines (75 loc) · 2.51 KB

🔥☕ 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