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

  • SEARCH
  • Home
  • 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 6016921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:03:12+00:00 2026-05-23T03:03:12+00:00

I have a DataMapper based SQLite database. I store the time at which the

  • 0

I have a DataMapper based SQLite database. I store the time at which the data upon which the model is built as Msrun.rawtime or a property :rawtime, DateTime, of the Model Msrun.

What I need to be able to do is select a date/time range in a filter, and then sort the DataMapper entries according to that time filter. Like this:

Msrun.all.size # => 63
matches = Msrun.all( begintime: 2010-11-03T21:33:00-0600, endtime: 2011-04-09T23:59:59-0600 )
matches.size # => 12

As my database has ~500 properties between this and submodels, and I expect to generate ~100 of these entries per month, I would like something that is really fast too. Is that going to require SQL? Is this possible? Am I making this harder than it should be/is there an easier way to configure my data to enable this type of sort?

  • 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-23T03:03:13+00:00Added an answer on May 23, 2026 at 3:03 am

    I’m not sure what is you want to do? If you want to query for items that happen between a particular start and end time, you can use:

    Mrsun.all(:rawtime => start_time..end_time)
    

    This will generate SQL something like

    SELECT ... FROM msruns WHERE rawtime > start_time AND rawtime < end_time;
    

    Does that answer your question?

    A fuller example:

    require 'rubygems'
    require 'dm-core'
    require 'dm-migrations'
    
    
    # setup the logger
    DataMapper::Logger.new($stdout, :debug)
    
    # connect to the DB
    DataMapper.setup(:default, 'sqlite3::memory:')
    
    class Msrun
      include DataMapper::Resource
    
      # properties
      property :id, Serial
      property :rawtime, DateTime
    
    end
    
    DataMapper.finalize.auto_migrate!
    
    
    10.times do |n|
      Msrun.create(:rawtime => DateTime.new(2011, 1, 1, 0, 0 , n))
    end
    
    p Msrun.all(:rawtime => DateTime.parse('2011-1-1T00:00:04+0100')..DateTime.parse('2011-1-1T00:00:07+0100'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model in datamapper: class Student include DataMapper::Resource property :id, Serial
I have a database schema like that DataMapper.setup :default, sqlite://#{Dir.pwd}/image.db class Image include DataMapper::Resource
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have an DataMapper class which has some private and public methods. The DataMapper
Just using DataMapper for the first time. I have set up a table in
In Ruby/Sinatra with DataMapper and dm-types, in a model hook I have this block
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
I'm using the data mapper pattern in a PHP app I'm developing and have
I'm working with Datamapper which allows you to specify either a path to a
Firstly, how can I have jQuery continuously check the time, and add an id

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.