Effect CommunityEC
Effect Community2y ago
2 replies
elchapitan

passing an arbitrary sized array into pipe

Hey there --

I'm trying to build a poor man's plugin system for building some queries in an AWS lambda endpoint. Specifically, I'm trying to build some pagination/sorting/filtering that can be passed in through query parameters. My idea was to have a base query provided, and then use a set of effect plugins that would modify the existing query into what i want using kysely. (we already have it set up, no reason to introduce new things now).

My first attempt was looking something like this:

    Effect.flatMap(({groupIdentifier}) => {
      return Effect.tryPromise({
        try: () =>
          paginator(
            listItemsBaseQuery(groupIdentifier),
            [
              applyPagination(event),
              applySort(event),
              applyFilter(event)
            ]
          ),
        catch: handleDBError,
      });
    }),


You can ignore the naming for right now, as I'm just trying to play this concept out. The idea is that the paginator function takes that first query, and then uses the Kysely query builders to add extra pieces depending on which of those modifier plugins were provided. So, pagination basically sets the window size and offset; sort applies the order by, grouping, etc and the filter would allow you to filter some simple ability to weed out some data.

Underneath the hood, the paginator function would construct the full query using that array of modifier plugins and run it against the database.

What I'm currently having an issue with is that the array is an arbitrary size, and I can't figure out how to use pipe to make it happen.

Am I trying to do this in the wrong way? Is there an easier to way to go about it?

Thanks!
Was this page helpful?