Quantcast

Gist with array -> encodesql

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gist with array -> encodesql

Jolle Carlestam-2
Greetings!

I’ve added a gist with a method to run encodesql on each item in a provided array or staticarray.

Can be found here:
https://gist.github.com/jolle-c/693b0cb599482a34d0cf8ee7d59e9fbc


This is the code:
/**!
array -> encodesql

Adds a method to the lasso 9 array and staticarray types that will run encodesql on each item in the array.
This changes the array in place.
It also alters each item to type string.

EXAMPLE USAGE
local(ids = array('1', '5', '22'))
local(sql = "SELECT * FROM mytable AS mt
WHERE mt.id IN ('" + #ids -> encodesql& -> join("', '") + "');")

*/
define array -> encodesql() => {
        loop(.size) => {
                if(.get(loop_count) -> isa(::pair)) => {
                        .get(loop_count) = pair(.get(loop_count) -> first -> asstring -> encodesql, .get(loop_count) -> second -> asstring -> encodesql)
                else
                        .get(loop_count) = .get(loop_count) -> asstring -> encodesql
                }
        }
}

define staticarray -> encodesql() => {
        loop(.size) => {
                if(.get(loop_count) -> isa(::pair)) => {
                        .get(loop_count) = pair(.get(loop_count) -> first -> asstring -> encodesql, .get(loop_count) -> second -> asstring -> encodesql)
                else
                        .get(loop_count) = .get(loop_count) -> asstring -> encodesql
                }
        }
}


--------------------
Hope it can be use use for someone.

HDB
Jolle

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Loading...