0

I have firebase already initialized in my app.module.ts with the config and all of that, and im going to use fireSQL to get items from my database because i like mySQL code to make this things, but the problem is that the page about fireSQL on firebaseopensource.com says that you have to declare fireSQL like this:

firebase.initializeApp({config});
const fireSQL = new FireSQL(firebase.firestore());

And i dont want to do this, initialize here firebase again, is there a way to change "firebase.firestore()" to something that takes the already initialized firebase?

EDIT: another solution for my problem would be knowing how to do this query in firebase query:

$query = "SELECT * FROM " . ITEMS_TABLE . " WHERE (category LIKE '%".$category."%' AND (title LIKE '%" . $text . "%' OR description LIKE '%" . $text . "%')) ORDER BY ".$orderby." ".$ascdesc;

It's in PHP, not typescript because is from another project that i m transforming to angular

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Sebas
  • 71
  • 1
  • 10

1 Answers1

0

It looks like new FireSQL(...) takes any instance of Firestore. When you do call new FireSQL(firebase.firestore()) it creates or gets the Firestore object fro the default FirebaseApp object. So if you've previously created a default (unnamed) FirebaseApp, the firebase.firestore() code will retrieve the Firestore service from that same object.

If you have another non-default instance FirebaseApp or Firestore already, you can pass in in to FireSQL like this: new FireSQL(myApp.firestore()) or new FireSQL(myFirestore).


You won't be able to run an exact equivalent of that query on Firestore, because Firestore doesn't support title LIKE '%" . $text clauses. See:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • im gonna try that, but im having problems with the queries (i was trying fireSQL puting the config there to see how it is) its not possible to use LIKE %value% in fireSQL, so i'll have problems. – Sebas Apr 26 '20 at 17:20
  • do u know how to do the query i posted in mySQL code into firebase query? – Sebas Apr 26 '20 at 17:21
  • I added a section to my answer for that. Note that on Stack Overflow you should limit yourself to one question per post, as it increases the chances someone can help, and decreases the chance that your post will get closed/downvoted. – Frank van Puffelen Apr 26 '20 at 17:26
  • im struggeling so much with the query, how would the query be if u change the "like %value%" to "value%"? – Sebas Apr 26 '20 at 18:25
  • The questions I linked show examples of that. If you're having a hard time making that work for your case, show the [minimal code that reproduces where you got stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen Apr 26 '20 at 19:14