GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - yesodweb/persistent: Persistence interface for Haskell allowing multiple storage methods.

BranchesTags
Open more actions menu

Latest commit

 

History

3,048 Commits
3,048 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
bin
bin
 
 
docs
docs
 
 
persistent-mongoDB
persistent-mongoDB
 
 
persistent-mysql
persistent-mysql
 
 
persistent-postgresql
persistent-postgresql
 
 
persistent-qq
persistent-qq
 
 
persistent-redis
persistent-redis
 
 
persistent-sqlite
persistent-sqlite
 
 
persistent-template
persistent-template
 
 
persistent-test
persistent-test
 
 
persistent
persistent
 
 
travis
travis
 
 
.dockerignore
.dockerignore
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
.restyled.yaml
.restyled.yaml
 
 
.travis.yml
.travis.yml
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
cabal.project
cabal.project
 
 
development.md
development.md
 
 
docker-compose.yml
docker-compose.yml
 
 
flake.lock
flake.lock
 
 
flake.nix
flake.nix
 
 
fourmolu.yaml
fourmolu.yaml
 
 
justfile
justfile
 
 
sources.txt
sources.txt
 
 
stack-8.10.yaml
stack-8.10.yaml
 
 
stack-8.10.yaml.lock
stack-8.10.yaml.lock
 
 
stack-docker.yaml
stack-docker.yaml
 
 
stack-nightly.yaml
stack-nightly.yaml
 
 
stack.yaml
stack.yaml
 
 
stack_lts-12.yaml
stack_lts-12.yaml
 
 

Repository files navigation

Persistent Build Status Hackage Hackage-Deps Join the chat at https://gitter.im/yesodweb/persistent

A Haskell datastore. Datastores are often referred to as "ORM"s. While 'O' traditionally means object, the concept can be generalized as:

avoidance of boilerplate serialization

In addition , the ORM concept is a way to make what is usually an un-typed driver type-safe. In dynamic languages rather than compile time errors, safety comes from creating specific dynamic errors rather than sending nonsense queries to the database.

Persistent's goal is to catch every possible error at compile-time, and it comes close to that.

Quickstart

Click to show package.yaml part. Learn more at http://www.yesodweb.com/book/persistent.
dependencies:
- base ^>= 4.17
- text ^>= 2
- persistent ^>= 2.14
- persistent-sqlite ^>= 2.13

{-# LANGUAGE EmptyDataDecls             #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE QuasiQuotes                #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeFamilies               #-}
import           Control.Monad.IO.Class  (liftIO)
import           Database.Persist
import           Database.Persist.Sqlite
import           Database.Persist.TH
import           Data.Text

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
    name Text
    age Int Maybe
    deriving Show
|]

main :: IO ()
main = runSqlite ":memory:" $ do
    -- setup db schema
    runMigration migrateAll
    
    -- write to db
    insert $ Person "Jane Doe" Nothing
    johnId <- insert $ Person "John Doe" $ Just 35

    -- read from db
    john1 <- selectList [PersonId ==. johnId] [LimitTo 1]
    john2 <- get johnId

    liftIO $ print (john1 :: [Entity Person])
    liftIO $ print (john2 :: Maybe Person)
    
    -- delete from db
    delete johnId
    deleteWhere [PersonId ==. johnId]

Backend agnostic

Supports PostgreSql, Sqlite, MongoDB, Redis, ZooKeeper, and many other databases via persistent-odbc. The MySQL backend is in need of a maintainer. Currently there are issues with migrations and support for composite and primary keys is lacking.

Persistent is designed to be adaptable to any datastore, and to allow multiple datastores to be used simultaneously. The serialization layer should be adaptable to any datastore.

Providing a universal query layer will always be limiting. A major limitation for SQL databases is that the persistent library does not directly provide joins. However, you can use Esqueleto with Persistent's serialization to write type-safe SQL queries. Key-value stores such as Redis can be used with persistent, but only fill out the key-value portion of the API (PersistStore) rather than the query portion (PersistQuery).

Persistent provides several hooks to create backend-specific functionality. One can always fall back to using the raw database driver or other lower-level or less type-safe libraries and can utilize Persistent for un-serializing the database response to a Haskell record.

Help improve Persistent

To install from source clone the repo and run stack build to build all targets. Persistent supports many backends. If you have only some of these installed the development doc shows how to build against a subset of targets.

For more information on how to hack on the persistent set of libraries, see the development.md file.

About

Persistence interface for Haskell allowing multiple storage methods.

Resources

Readme
MIT license

Contributing

Contributing
Activity
Custom properties

Stars

486 stars

Watchers

21 watching

Forks

307 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.