coast-framework / lighthouse Goto Github PK
View Code? Open in Web Editor NEWEasy clojure relational database queries, migrations and connection pooling
License: MIT License
Easy clojure relational database queries, migrations and connection pooling
License: MIT License
Hi,
In your example on joins :
(db/q conn '[:select todo/* person/*
:from todo
:joins person/todos])
We get the error
PSQLException ERROR: table name "todo" specified more than once org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2440)
Don't you think it should be simply
(db/q conn '[:select todo/* person/*
:joins person/todos])
?
In addition, it could be useful to have a way to get the real SQL query generated underneath. Would it be possible?
In the same vein, how do you use multiple joins?
E.g.
(def todos-users [{:db/col :person/name :db/type "text" :db/unique? true :db/nil? false}
{:db/col :item/name :db/type "text" :db/unique? true :db/nil? false}
{:db/rel :item/todos :db/type :many :db/ref :todo/item}
{:db/rel :todo/item :db/type :one :db/ref :item/id}
{:db/rel :person/todos :db/type :many :db/ref :todo/person}
{:db/rel :todo/person :db/type :one :db/ref :person/id}
{:db/col :todo/name :db/type "text"}
{:db/col :todo/done :db/type "boolean" :db/default false :db/nil? false}])
(db/migrate conn todos-users)
(db/q conn '[:select todo/* :joins person/todos item/todos])
PSQLException ERROR: table name "todo" specified more than once org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2440)
Thanks
Hi,
defq
as defined is not a macro but a function.
However you use ~
in its body. I saw that when trying to use it unsuccessfully.
Based on your code in https://github.com/coast-framework/coast, something like this works better for me :
(defmacro defq
([conn-pool n filename]
`(let [q-fn# (lighthouse.defq/query-fn ~conn-pool (assoc (lighthouse.defq/query ~(str n) ~filename) :ns *ns*))]
(lighthouse.defq/create-root-var ~(str n) q-fn#)))
([conn-pool filename]
`(lighthouse.defq/query-fns ~conn-pool ~filename)))
Any opinion on that?
Thanks,
jerome
Hey, JFYI, sqlite as of 3.25 also supports postgres' ON CONFLICT DO syntax, which allows for upserting and therefore transacting. I implemented this yesterday for python, if you're curious you can rifle through the code and steal what you want. Most of it is inspired by coast anyway ;)
https://gist.github.com/mgerlach-klick/0044a0e7e98b20002e967d495a8d79c7#file-db-py-L65
Hi, (lighthouse.core/insert conn {:person/name "Gen Eric"})
returns (1) if it succeded. In the readme at insert I found this: "p is auto-resolved to (get p :person/id)". So what do I misunderstand? how can I get back the id of the inserted row? Thank you, appreciating your work!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.