Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:06+00:00 2026-05-26T16:56:06+00:00

We are using Datamapper in a Sinatra application and would like to use case

  • 0

We are using Datamapper in a Sinatra application and would like to use case insensitive like that works on both Sqlite (locally in development) and Postgresql (on Heroku in production).

We have statements like

TreeItem.all(:name.like =>"%#{term}%",:unique => true,:limit => 20)

If termis “BERL” we get the suggestion “BERLIN” from both the Sqlite and Postgresql backends. However if termis “Berl” we only get that result from Sqlite and not Postgresql.

I guess this has to do with the fact that both dm-postgres-adapter and dm-sqlite-adapter outputting a LIKE in the resulting SQL query. Since Postgresql has a case sensitive LIKE we get this (for us unwanted) behavior.

Is there a way to get case insensitive like in Datamapper without resorting to use a raw SQL query to the adapter or patching the adapter to use ILIKEinstead of LIKE?

I could of course use something in between, such as:

TreeItem.all(:conditions => ["name LIKE ?","%#{term}%"],:unique => true,:limit => 20)

but then we would be tied to the use of Postgresql within our own code and not just as a configuration for the adapter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:56:07+00:00Added an answer on May 26, 2026 at 4:56 pm

    By writing my own data object adapter that overrides the like_operator method I managed to get Postgres’ case insensitive ILIKE.

    require 'do_postgres'
    require 'dm-do-adapter'
    
    module DataMapper
      module Adapters
    
        class PostgresAdapter < DataObjectsAdapter
    
          module SQL #:nodoc:
            private
    
            # @api private
            def supports_returning?
              true
            end
    
            def like_operator(operand)
              'ILIKE'
            end
          end
    
          include SQL
    
        end
    
        const_added(:PostgresAdapter)
    
      end
    end
    

    Eventually I however decided to port the application in question to use a document database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a very simple timeshare application using Sinatra and Datamapper. Every user in
I'm building a small Ruby application using DataMapper and Sinatra, and I'm trying to
I am working on a simple budget app using Sinatra and DataMapper in Ruby.
I am trying to call a select statement using datamapper in sinatra. here is
I have a basic Ruby app that I am building with Sinatra, Datamapper and
I have a padrino install that is using datamapper and logging queries to a
DataMapper appears to be generating grossly sub-optimal queries for associations that use a join
I use datamapper and postgres for my ror application, in my models i have
I'm using Sinatra, EventMachine, DataMapper, SQLite3 and the Twitter Stream API to capture and
I'm using Datamapper 1.0 with sinatra and sqlite3 as backend. I have some devices,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.