maca/postgrest-admin-preview/2.0.0

NOTE: the latest version is 15.0.0

Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/maca/postgrest-admin-preview.

What we checked: Rebuilt with git archive from commit 350230029a04 of https://github.com/maca/postgrest-admin-preview (zip prefix maca-postgrest-admin-preview-3502300/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 c459b29923385a955494589b92aea9c5c0ab9488.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/maca/postgrest-admin-preview/zipball/2.0.0/

PostgRestAdmin.Client

Client

type alias Client =
Client

Represents a client for a PostgREST instance, including authentication params.

See Config and Config.FormAuth for authentication configuration options.

toHostUrl : Client -> Url

Obtain the PostgREST instance url.

Table

type alias Table =
Table

Represents a PostgREST table.

getTable : String -> Client -> Maybe Table

Obtain a table from the table name.

Requests

Note that the request functions do not produce a vanilla Elm Cmd but a PostgRestAdmin.Cmd.

{ client : Client
, table : Table
, id : String
, expect : Result Error Value -> msg
}
-> Cmd msg

Fetches a record for a given table. expect param requires a function that returns a Msg.

You can use expectRecord to interpret the result as a Record.

import PostgRestAdmin.Cmd as AppCmd


fetch : String -> Client -> AppCmd.Cmd Msg
fetch tableName client =
    case getTable tableName client of
        Just table ->
            fetchRecordList
                { client = client
                , table = table
                , params = []
                , expect = Client.expectRecord MyFetchedMsg table
                }


        Nothing ->
            AppCmd.none
{ client : Client
, table : Table
, params : Params
, expect : Result Error Value -> msg
}
-> Cmd msg

Fetches a list of records for a given table. expect param requires a function that returns a Msg.

You can use expectRecordList to interpret the result as a list of Records.

import PostgRestAdmin.Cmd as AppCmd


fetchList : String -> Client -> AppCmd.Cmd Msg
fetchList tableName client =
    case getTable tableName client of
        Just table ->
            fetchRecordList
                { client = client
                , table = table
                , params = []
                , expect = Client.expectRecordList MyListFetchedMsg table
                }


        Nothing ->
            AppCmd.none
{ client : Client
, record : Record
, id : Maybe String
, expect : Result Error Value -> msg
}
-> Cmd msg

Saves a record. expect param requires a function that returns a Msg.

You can use expectRecord to interpret the result as a Record.

import PostgRestAdmin.Cmd as AppCmd


save : Record -> Maybe String -> Client -> AppCmd.Cmd Msg
save record id client =
    saveRecord
        { client = client
        , record = record
        , id = id
        , expect =
            Client.expectRecord MySavedMsg
                (Record.getTable record)
        }
{ client : Client
, record : Record
, expect : Result Error Value -> msg
}
-> Cmd msg

Deletes a record. expect param requires a function that returns a Msg.

You can use expectRecord to interpret the result as a Record.

import PostgRestAdmin.Cmd as AppCmd


save : Record -> Client -> AppCmd.Cmd Msg
save record client =
    deleteRecord
        { client = client
        , record = record
        , expect =
            Client.expectRecord MyDeletedMsg
                (Record.getTable record)
        }
{ path : String
, client : Client
, value : Value
, expect : Result Error Value -> msg
}
-> Cmd msg

POST to a PostgREST path.

The path can identify a plural resource such as /posts in which case an upsert operation will be performed, or a singular resource such as '/posts?id=eq.1'.

type alias Error =
Error

Request error.

errorToString : Error -> String

Transform Error to an error explanation.

Result interpreting

expectRecord : (Result Error Record -> msg) -> Table -> Result Error Value -> msg

Decode the Value for successful Result as a record, decode as such and map the success of the Result to a msg.

(Result Error (List Record) -> msg)
-> Table
-> Result Error Value
-> msg

Decode the Value for successful Result as a list of records, decode as such and map the success of the Result to a msg.

See fetchRecordList.

Authentication

isAuthenticated : Client -> Bool

Does the client has a valid JWT?

toJwtString : Client -> Maybe String

Obtain the JWT as a string.