Skip to content

blaix/gren-ws4sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLite for Gren

Use sqlite entirely in Gren without ports via ws4sql.

Usage Example

Start a ws4sql database server (this will create the sqlite db if it doesn't exist):

npx ws4sql --quick-db /path/to/mydatabase.db

Then you can write code like:

import Db
import Db.Encode
import Db.Decode
import HttpClient

type alias User =
    { id : Int
    , name : String
    }

getUser : HttpClient.Permission -> Int -> Task Db.Error User
getUser httpPerm userId =
    let
        connection =
            Db.init httpPerm "http://localhost:12321/mydatabase"
    in
    Db.getOne connection
        { query = "select * from users where id = :id"
        , parameters = [ Db.Encode.int "id" userId ]
        , decoder = 
            Db.Decode.map2
                (Db.Decode.int "id")
                (Db.Decode.string "name")
                (\id name -> { id = id, name = name })
        }

More Info

See the package docs for full usage details.

Running npx ws4sql --quick-db as in the example above lets you try out ws4sql without installing or configuring anything. For full details on installing, configuring, and running ws4sql, see the ws4sql-npm package and the ws4sqlite repo. Note: this package expects the ws4sql fork of ws4sqlite (this is what is installed by the npm package).

About

Use sqlite with Gren through ws4sql

Resources

License

Stars

Watchers

Forks

Packages

No packages published