PsychicPlatypus

PsychicPlatypus

Link to HexDocs Page

Motivation

I was building a toy rest-api using plug-cowboy and wanted a way to turn query parameters such as name: "Bob, age: 15 into sql statements such as:

Depo.read("SELECT * FROM customers WHERE" <> "name = ? AND age = ?", "Bob", 15)

in a simple way

Usage

ExtractQueryParams.to_variables(name: "Bob", age: 15)
{"name= ? AND age = ?", ["Bob", 15]} #returns

The default logical operator is AND but you can also specify which operator you want:

ExtractQueryParams.to_variables([name: "Bob", age: 15], "OR")
{"name= ? OR age = ?", ["Bob", 15]} #returns

Feel free to leave any feedback or contribute if you want!

Showing Posts 1 to 3

gregvaughn

gregvaughn

Are you intentionally wanting to avoid Ecto? With Ecto and a schema defined for Customer creating the query becomes a one-liner

filters = [name: "Bob", age: 15]
query = from c in Customer, where: ^filters
PsychicPlatypus

PsychicPlatypus OP

In cases you want to write raw sql queries with something like Depo and SQlite3 without using ecto

gregvaughn

gregvaughn

No. I don’t personally want to exchange Ecto for string concatenation. I’ll step out of the thread since I’m not part of your potential audience. Best wishes to you!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews