项目作者: joshday

项目描述 :
Read/write Google Firestore documents from Julia
高级语言: Julia
项目地址: git://github.com/joshday/Firestore.jl.git
创建时间: 2021-03-29T18:25:07Z
项目社区:https://github.com/joshday/Firestore.jl

开源协议:MIT License

下载


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"] = "<my_project_id>".
    • 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

  1. using Firestore
  2. using Dates
  3. doc = Dict(
  4. :x1 => 1,
  5. :x2 => "a string",
  6. :x3 => Dict(:sub1 => 1, :sub2 => [1, "two"]),
  7. :x4 => false,
  8. :x5 => nothing,
  9. :now => now(),
  10. :today => today(),
  11. :x7 => [1, "two", Dict("three" => 3)]
  12. )
  13. # `patch` will overwrite an existing doc whereas `createDocument` will not
  14. Firestore.patch("test_collection/test_doc", doc)

Read

  1. Firestore.get("test_collection/test_doc")
  1. Dict{Symbol, Any} with 8 entries:
  2. :today => DateTime("2021-03-29T00:00:00")
  3. :x2 => "a string"
  4. :x5 => nothing
  5. :x7 => Any[1, "two", Dict(:three=>3)]
  6. :x3 => Dict{Symbol, Any}(:sub2=>Any[1, "two"], :sub1=>1)
  7. :x4 => false
  8. :now => DateTime("2021-03-29T14:21:17.409")
  9. :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"] = <your email> and ENV["FIRESTORE_PASSWORD"] = <your pw> 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"] = <Web API Key> to your ~/.julia/startup/config.jl
  3. Go to your Firebase “Firestore Database” page:

    • Copy/paste this to your “Rules”:
      1. // Allow read/write access on all documents to any user signed in to the application
      2. service cloud.firestore {
      3. match /databases/{database}/documents {
      4. match /{document=**} {
      5. allow read, write: if request.auth != null;
      6. }
      7. }
      8. }
  4. Call get_token!() and now your requests are authenticated!