Coder Social home page Coder Social logo

Comments (10)

yogthos avatar yogthos commented on June 2, 2024

Running (conman/bind-connection db "sql/queries.sql") will rebind the new connection to the queries. However, if you've compiled a jar, the queries.sql will be loaded relative to the resource path of the jar, not externally.

from conman.

csummers avatar csummers commented on June 2, 2024

@vinurs asked this same question of HugSQL, where you are able to use a java.io.File outside of the resource path. Since conman wraps HugSQL's map-of-db-fns, I initially assumed you could do the same for the specified file. Upon further inspection, though, it looks like conman is expecting a string file path.

layerware/hugsql#85

from conman.

yogthos avatar yogthos commented on June 2, 2024

Ah makes sense, I'll update to allow taking a File as well.

from conman.

vinurs avatar vinurs commented on June 2, 2024

@yogthos thanks very much, in HugSQL, there seems a option
that can prevent SQL injection, but in conman it seems doesn't support it, could you update it?

from conman.

yogthos avatar yogthos commented on June 2, 2024

Sure, what option are you referring to specifically?

from conman.

vinurs avatar vinurs commented on June 2, 2024

@yogthos this is the option:

By default, identifiers are not quoted. You can specify your desired quoting as an option when defining your functions or as an option when calling your function.

If you are taking identifiers from user input, you should use the :quoting option to properly quote and escape identifiers to prevent SQL injection!

Valid :quoting options are:

:ansi double-quotes: "identifier"
:mysql backticks: `identifier`
:mssql square brackets: [identifier]
:off no quoting (default)
Identifiers containing a period/dot . are split, quoted separately, and then rejoined. This supports myschema.mytable conventions.

(hugsql.core/def-db-fns "path/to/good.sql" {:quoting :ansi})

from conman.

yogthos avatar yogthos commented on June 2, 2024

I think that should already work, you can pass an options map as the first argument to bind-connection, e.g: (bind-connection conn {:quoting :ansi} "path/to/queries.sql").

from conman.

yogthos avatar yogthos commented on June 2, 2024

@vinurs I pushed out a new version 0.8.0 that supports loading queries from a file object. Unfortunately, this won't work with the bind-connection macro, so now there's a bind-connection-mapfunction that returns the map of generated queries and snippets. There are also a couple of helpers to make it easier to work with the map called snip and query. Usage looks as follows:

(def queries (bind-connection conn {:quoting :ansi} (java.io.File. "test/queries.sql")))

(query queries
            :add-fruit!
            {:name       "apple"
             :appearance "red"
             :cost       1
             :grade      1})

(query queries
           :get-fruit-by
           {:by-appearance
            (snip queries :by-appearance {:appearance "red"})})

Let me know if this looks good to you.

from conman.

vinurs avatar vinurs commented on June 2, 2024

@yogthos thanks very much, i'll try it.

from conman.

yogthos avatar yogthos commented on June 2, 2024

Looks like things are working on my end, so I'm going to close this. If anything comes up we can revisit.

from conman.

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.