Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A fully featured, data-driven database library for Clojure.

License

NotificationsYou must be signed in to change notification settings

kwrooijen/gungnir

Repository files navigation

A fully featured, data-driven database library for Clojure.

Build StatuscodecovDependencies StatusClojars ProjectSlack

It is said that Gungnir could strike any target, regardless of the wielder'sskill.

- Developer, speaking to the database admin.

Read the guide

Gungnir code playground

Dutch Clojure Meetup - Gungnir

(gungnir.database/make-datasource! {:adapter"postgresql":username"postgres":password"postgres":database-name"postgres":server-name"localhost":port-number5432})(defaccount-model  [:map   [:account/id {:primary-keytrue} uuid?]   [:account/email {:before-save [:string/lower-case]:before-read [:string/lower-case]}    [:re {:error/message"Invalid email"}#".+@.+\..+"]]   [:account/password {:before-save [:bcrypt]} [:string {:min6}]]   [:account/password-confirmation {:virtualtrue} [:string {:min6}]]   [:account/created-at {:autotrue} inst?]   [:account/updated-at {:autotrue} inst?]])(gungnir.model/register! {:account account-model})(defnpassword-match? [m]  (= (:account/password m)     (:account/password-confirmation m)))(defmethodgungnir.model/validator:account/password-match? [_]  {:validator/key:account/password-confirmation:validator/fn password-match?:validator/message"Passwords don't match"})(defmethodgungnir.model/before-save:bcrypt [_k v]  (buddy.hashers/derive v))(defnattempt-register-account [request]  (-> (:form-params request)      (gungnir.changeset/cast:account)      (gungnir.changeset/create [:account/password-match?])      (gungnir.query/save!)))(gungnir.query/find-by!:account/email"some@email.com");; => {:account/email "some@email.com",,,}(-> (gungnir.query/limit5)    (gungnir.query/select:account/id:account/email)    (gungnir.query/all!:account));; => [{:account/email "..." :account/id "..."},,,]

Installation

Gungnir is still in its design phase and can result in breaking changes while onthe SNAPSHOT version. Any breaking changes will be reflected in the updateddocumentation.

Add the following dependencies to yourproject.clj

Versions

:dependencies [[kwrooijen/gungnir"0.0.2-xxxxxxxx.yyyyyy-z"];; Optionally for frontend validation               [kwrooijen/gungnir.ui"0.0.2-xxxxxxxx.yyyyyy-z"]               ,,,]

Rationale

Plug & Play setup with quality of life

The Clojure community tends to lean towards the "pick the libraries that youneed" method rather than using a "framework" when building an application. Thiscan make it challenging for new users. Once you're familiar with the Clojureecosystem you'll know which libraries you prefer and create your own setup. Andthat's exactly what I've done.

If you want complete control over your database stack, then this is probably notfor you. If you're a beginner and are overwhelmed with all the necessarylibraries and configuration, or if you're looking for a Clojure database librarythat aims to provide a quality of life experience similar to Ruby's ActiveRecordor Elixir's Ecto, then stick around.

Data Driven

I cannot stress this enough, I really dislike macros. Clojure and a large partof it's community have taught me the beauty of writing data driven code. Withgreat libraries such as HoneySQL, Hiccup, Integrant, Reitit, Malli, I think thisis the Golden age of Data Driven Clojure. I never want to see macros in my APIagain.

Features

Plug & Play™

Include Gungnir in your project, and off you go! Gungnir includes everything foryour database needs.

Models

Gungnir uses models to provide data validation and seamless translation betweenClojure and SQL.Read more

Changesets

Inspired by Elixir Ecto's Changesets. Validate your data before inserting orupdating it in your database. View the actual changes being made, and aggregateany error messages.Readmore

Querying & Extension to HoneySQL

Gungnir isn't here to reinvent the wheel. Even though we have an interface forquerying the database, we can still make use of HoneySQL syntax. This allows usto expand our queries, or write more complex ones for the edge cases.Readmore

Migrations

Define your migrations using Clojure data structures and extend them asneeded. You can also fallback to raw SQL if necessary.Readmore

Relational mapping

Relations are easily accessed with Gungnir. Records with relations will haveaccess torelational atoms which can be dereffed to query any relatedrows.Readmore,and more

Frontend validation

Gungnir also provides an extra package,gungnir.ui. Which provides somevalidation in the frontend.Readmore

Resources

Guide

Read the guide for a fulloverview of all the features and how to use them.

Code Playground

TheGungnir code playgroundis a repository with an "interactive tutorial". Clone the repository and executethe code in the core namespace step by step.

Developing

Testing

In order to run the tests you'll needdocker-compose. Make sure thisis an up to date version. Inside of the root directory you can setup the testingdatabases with the following command.

docker-compose up -d

Then run the tests withlein

leintest

Author / License

Released under theMIT License byKevin William van Rooijen.

About

A fully featured, data-driven database library for Clojure.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

[8]ページ先頭

©2009-2025 Movatter.jp