Comments (9)
Why don't you want to write it out to a file?
from hugsql.
well, since the file is read by hugsql from the classpath i think there would need to be a build step to create it before deployment which is possible... but seems a bit of a hassle.
from hugsql.
I'm open to this enhancement. It would allow defining of hugsql functions coming from other sources than files (databases and others). I don't think I'd overload def-sqlvec-fns. I'll likely create another function/macro that takes a string or java.io.Reader.
from hugsql.
@ohlo, an undocumented feature of def-db-fns and def-sqlvec-fns is that they can take a java.io.File object that has a path outside of the classpath. It's undocumented because I wasn't sure if I wanted to keep this functionality, but now I think I probably do. You might give it a go until the 0.4.x release hits with your requested enhancement.
from hugsql.
thanks for the info. but... there seems to be a bug with that:
(condp isa? file
java.io.File file ; already file
java.net.URL file ; already resource
; assume resource path (on classpath)
(if-let [f (io/resource file)]
f
(throw (ex-info (str "Can not read file: " file) {})))
)
i think it should be instance? not isa? ... so. even if passing in a file it falls through to last statement.
from hugsql.
I think this is actually a macro issue leading to the condp fall-through. Looks like it was introduced with this commit: 79a1020
So, this will have to wait just a bit. I should have more bandwidth to tackle this in a few days.
Thanks for the report!
from hugsql.
that's ok, I have a workaround.
before calling (eval (list 'hugsql/def-db-fns my-temp-file))
in my code, i redefine the problem fn to use instance?
(in-ns 'hugsql.core)
;; temp redef of file. bug should be fixed shortly https://github.com/layerware/hugsql/issues/16
(defn ^:no-doc parsed-defs-from-file
"Given a hugsql SQL file, parse it,
and return the defs."
[file]
(parser/parse
(slurp
(condp instance? file
java.io.File file ; already file
java.net.URL file ; already resource
; assume resource path (on classpath)
(if-let [f (io/resource file)]
f
(throw (ex-info (str "Can not read file: " file) {})))))))
which works :-)
from hugsql.
Yes, instance?
is correct. (My error is a direct result of my Ruby history where is_a? and instance? differ from Clojure's semantics).
When I fix this and make support of java.io.File official, it will include docs and a test to prevent regressions. Thanks!
from hugsql.
As of the 0.4.0 release, you now have more options for defining database functions:
def-db-fns-from-string
and def-sqlvec-fns-from-string
take a HugSQL flavored string.
def-db-fns
and def-sqlvec-fns
now accept an existing java.io.File object properly.
The 0.4.0 refactor also added several functions that operate on individual SQL statements instead of entire files. See Other Useful Functions
from hugsql.
Related Issues (20)
- Taking array as an input
- Not able to update multiple column values
- Optional null parameters HOT 1
- Way to get generated SQL without executing? HOT 1
- Add support for next.jdbc.sql/insert-multi! HOT 1
- Avoid calling apply in 'hugsql.adapter.clojure-java-jdbc' HOT 5
- Incorrect Arities Shown in Docs for def-fb-fns HOT 1
- HugSql fails during AOT compilation with depstar HOT 4
- Switch to newer groupId of next.jdbc dependency in hugsql-adapter-next-jdbc HOT 1
- How to use a function from the database? HOT 2
- Migration fails if a comment is present on line with semicolon HOT 2
- Babashka support HOT 2
- No comments in doc on mobile? HOT 1
- Using classpath resource sql functions breaks cider HOT 3
- Hugsql 0.5.3 still requires SQL files on uberjar compilation (with leiningen) HOT 1
- strange key with jsonb HOT 3
- Should hugsql switch to next.jdbc by default ? HOT 2
- Cannot look up by UUID HOT 2
- Bulk update? HOT 1
- Inline parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hugsql.