https://github.com/joshday/firestore.jl
Read/write Google Firestore documents from Julia
https://github.com/joshday/firestore.jl
api-client firestore julia
Last synced: 8 months ago
JSON representation
Read/write Google Firestore documents from Julia
- Host: GitHub
- URL: https://github.com/joshday/firestore.jl
- Owner: joshday
- License: mit
- Created: 2021-03-29T18:25:07.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-01T17:29:12.000Z (about 5 years ago)
- Last Synced: 2025-02-01T09:31:54.383Z (over 1 year ago)
- Topics: api-client, firestore, julia
- Language: Julia
- Homepage:
- Size: 26.4 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Firestore.jl
This package provides utilities for reading & writing Google Firestore documents with Julia using the REST API.
This package is unofficial and not sponsored or supported by Google.
## Setup
1. Create a new Firebase project at https://firebase.google.com.
2. Create a Firestore Database in your project.
3. In your `.julia/startup/config.jl` file, add `ENV["FIRESTORE_PROJECT"] = ""`.
- Alternatively, use `Firestore.set_project!(::String)`.
## High-Level Usage
Firestore supports the following datatypes (in Julia-speak):
- `Bool`
- `Int64`
- `Float64`
- `Nothing`
- `String`
- `DateTime`
- `Dict{String, SupportedType}`
- `Vector{SupportedType}`
Firestore.jl will convert your data into the appropriate type if it is able to do so (e.g. `OrderedDict` -> `Dict`).
### Write
```julia
using Firestore
using Dates
doc = Dict(
:x1 => 1,
:x2 => "a string",
:x3 => Dict(:sub1 => 1, :sub2 => [1, "two"]),
:x4 => false,
:x5 => nothing,
:now => now(),
:today => today(),
:x7 => [1, "two", Dict("three" => 3)]
)
# `patch` will overwrite an existing doc whereas `createDocument` will not
Firestore.patch("test_collection/test_doc", doc)
```
### Read
```julia
Firestore.get("test_collection/test_doc")
```
```
Dict{Symbol, Any} with 8 entries:
:today => DateTime("2021-03-29T00:00:00")
:x2 => "a string"
:x5 => nothing
:x7 => Any[1, "two", Dict(:three=>3)]
:x3 => Dict{Symbol, Any}(:sub2=>Any[1, "two"], :sub1=>1)
:x4 => false
:now => DateTime("2021-03-29T14:21:17.409")
:x1 => 1
```
## Supported Operations
See https://firebase.google.com/docs/firestore/reference/rest#rest-resource:-v1beta1.projects.databases.documents.
- `createDocument`
- `delete`
- `get`
- `patch`
## Authentication
- NOTE: Currently only email/password-based auth is supported.
### Authenticating Only Yourself
1. Go to your Firebase "Authentication" page:
- Under "Sign-In Method", enable the "Email/Password" provider.
- Under "Users", add your email and password.
- Add `ENV["FIRESTORE_EMAIL"] = ` and `ENV["FIRESTORE_PASSWORD"] = ` to your `~/.julia/startup/config.jl` file.
2. Go to your Project Settings (Click the cog next to "Project Overview") page:
- Add `ENV["FIRESTORE_API_KEY"] = ` to your `~/.julia/startup/config.jl`
3. Go to your Firebase "Firestore Database" page:
- Copy/paste this to your "Rules":
```
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
```
4. Call `get_token!()` and now your requests are authenticated!