Giter Club home page Giter Club logo

Comments (9)

robinheghan avatar robinheghan commented on July 24, 2024

Why don't you want to write it out to a file?

from hugsql.

henryw374 avatar henryw374 commented on July 24, 2024

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.

csummers avatar csummers commented on July 24, 2024

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.

csummers avatar csummers commented on July 24, 2024

@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.

henryw374 avatar henryw374 commented on July 24, 2024

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.

csummers avatar csummers commented on July 24, 2024

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.

henryw374 avatar henryw374 commented on July 24, 2024

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.

csummers avatar csummers commented on July 24, 2024

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.

csummers avatar csummers commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.