I want to populate my Cloud Firestore from some .csv files. To do that, I would like to write a Dart program to run on Linux.
In order to reuse my code, I was wondering if it is possible to use FlutterFire SDK in a Dart program that doesn't use Flutter at all.
If it is possible, how can I set up Firebase and FlutterFire?
Related
First, it is possible to write firebase cloud functions in dart.
For that we need
write cloud functions using https://github.com/pulyaevskiy/firebase-functions-interop
compile dart to js code
move compiled code to firebase functions folder
then run firebase emulators as usual
Is it possible to set breakpoints in dart code in the firebase functions emulator?
My use case
using this library https://github.com/pulyaevskiy/firebase-functions-interop
I want to port my firebase functions from TypeScript to Dart but one of the concerns I have now is debugging
How I can debug dart code in the firebase emulator?
In my typescript project
I run this command tsc -w | firebase emulators:start --only functions --inspect-functions
and can set breakpoints in VSCode
But how it will work with https://github.com/pulyaevskiy/firebase-functions-interop in dart?
So I'm currently making a webscraper app, and i have some weird responses which i want to examine. But of course it more than 7000 characters since it is an html so i can't simply just print() it. Is there any way to save Strings created runtime?
My suggestion would be to extract your HTTP/webscraping code into a plain Dart package, and then to make your Flutter app dependent on your new package.
A Dart package is a self-contained library in which you can provide the library code, together with test routines and examples of how to use it. The beauty of this is that you could write an example that exercised part of your library, perhaps grabbing the raw data - and it could write it to a file. Equally, you could use the Dart debugger to inspect variables. Note that you should download and install the Dart SDK to your PC - don't try to use the one bundled in the flutter installation. You'll find that you can test the bulk of your parsing logic without even using a mobile device or emulator.
Create the Dart package in a sibling folder of the Flutter app and refer to it in the app's pubspec.yaml with (assuming you called your package 'scraper'):
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^0.1.2
scraper:
path: ../scraper
You can save to a .txt fairly easily and within the project for you to comb through.
This link regarding reading and writing files should help
I'm writing a script for setting up a Google Cloud project and I'd like to use Firestore. A new project, however, is by default in Datastore mode.
Switching to Firestore can easily be done using the web interface in the cloud console but I'd like to automate it. Is there any API or command line tool (gcloud? firebase?) for enabling it?
Unfortunately, as of today (30 Apr 2019), there is no API or command line to set the mode for Cloud Firestore.
Things seem to have changed by now (03 Jan 2022). I managed to set up a new Firestore with gcloud using the following commands.
Native mode is chosen by default:
gcloud app create --region=us-central
gcloud firestore databases create --region=us-central
also see the documentation for
app create and firestore database create.
Context, I have a project with datastore which already has information loaded, currently we wanted to use cloud firestore (native mode), but we realized that migration is not possible, what alternatives do I have to use cloud firestore (native mode)?
Update June 16, 2021:
You can now do gcloud datastore export in your first project, followed by gcloud firestore import in your new project. The longer more involved migration below is no longer needed.
Just keep in mind that the Datastore export goes to a Cloud Storage bucket. Make sure that the account running the Firestore import has access to that bucket.
Original answer from 2019
I just migrated from Datastore to Firestore (native mode) for one of my web apps. Here is what I needed to do:
Create a new GCP project, as Firestore (native mode) and Datastore
can't co-exist in the same project.
Migrate the data from Datastore in my old project to Firestore (native mode) in my new project. As of this writing, there are no tools to do that in an automatic way. I wrote Python scripts that read all records from Datastore and wrote them to Firestore in the new project. These scripts ran locally on my machine, using service account keys downloaded from the Cloud Console.
(Side note: You might be tempted to use gcloud datastore export followed by gcloud firestore import. It seems to work and no error messages pop up when you do. But doc IDs and JSON properties don't translate well. This was a big time-sink for me. Don't go down this road.)
Rewrite the data access layer in your app. Firestore (native mode) has a different API than Datastore.
This was a fair amount of work, but it was worth it in my case:
I was able to retire a lot of server-side code because the clients can access the database directly.
I was able to retire a lot of client-side code for supporting offline mode because the Firestore client library implements it already.
Best of luck!
Unfortunately, you'll need to create your Cloud Firestore database in a new project that allow your existing service accounts to access that new database.
Is there a command or parameter to disable FireBase's storage option? I never need it and it adds extra time to the deployment process that I don't need. Or should I just create a new project and start over?
Thanks.
Simply do not implement the storage library into your gradle file, then your app will not connect at all with Firebase Storage and your build will be a slightly faster since it won't be loading all Firebase Storage library