railsmechanic

railsmechanic

Hi!

I’m currently planning a proof of concept Phoenix web application, which should utilize CouchDB as its main database. I’ve some experience with CouchDB and I understand how to model the documents for my application.

Now, my main problem is how to handle user inputs. When users submit a form, all parameters are just strings. With ecto it’s quite simple as we can use a specific schema to cast these inputs to the correct data types e.g. integers, floats etc. But how to handle this without ecto? I need to cast user inputs to a struct, with the correct data types, which can be used within the application and to store (encoded to JSON) within CouchDB.

One option is to (ab)use a ecto schema for casting an validating the user inputs. But are there other options I can use? I’m searching for a couple of days but I don’t find anything suitable. Mostly some proof of concepts like “Parse, don’t validate”, which describes (mostly in theory) how to tackle this problem.

Do you have any hints for me?

Many thanks!

Showing Posts 1 to 3

lud

lud

That would be my first attempt honestly. Once you have a changeset you can write your own logic for persistence. And schemas are useful anyway.

Or you could use a library like Xema. But for example you will still have to cast string-integers to integers, which means that you will have to validate those with custom validators or regexes.

I did not read the entire article you linked but to me validating before inserting makes no sense anyway. Just “validate” right after receiving the data (welll … the input) should be enough.

wmnnd

wmnnd

Ecto has been purposefully split into ecto and ecto_sql. So it’s definitely not an “abuse” to use Ecto simply for handling and casting user-provided data when you’re not working with an SQL database.
You can use all the lovely features of Changesets including integration with Phoenix, even if you’re using your own persistence layer.

gregvaughn

gregvaughn

I’ll echo the other messages. It is not abuse to use ecto without persistence. I gave a talk a couple of years ago “Ecto Without a DB” that has an example of validating user input for search params. Here’s the video queued to that section.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews