Questions tagged [ruby-datamapper]

DataMapper is a Object Relational Mapper written in Ruby. It implements an architectural pattern with the same name (with some changes).

Key features of Datamapper:

  • query chaining (delaying actual talking to a DB until necessary)
  • bulk loading of several data rows with one query
  • very abstract design allowing non-SQL adapters
  • lazy loading of large fields

Home page http://datamapper.org/

242 questions
3
votes
1 answer

Ruby and Sinatra, unable to compare hashed password with BCrypt

i'm developing a simple Ruby authentication app with Sinatra and DataMapper. I have successfully implemented an hashing password method for when the users get registered, but i'm unable to get the authentication route to work, it simply doesn't…
3
votes
1 answer

'Error: Cannot open "/home/<...>/billy-bones/=" for reading' while using pry and DataMapper

So, I'm trying to build a quick console program for my development needs, akin to rails console (I'm using Sinatra + DataMapper + pry). I run it and launch cat = Category.new(name: 'TestCat', type: :referential). It gives me the following…
art-solopov
  • 2,867
  • 2
  • 18
  • 39
3
votes
1 answer

How do I improve performance of SQLite3 in Datamapper?

I am working in SQLite3 using DataMapper. I was populating a table with almost 1.4 million records and it was taking a long time. I found out that inserts in SQLite are inherently slow and can be improved by: Setting pragma Synchronous = OFF Doing…
bhuwansahni
  • 1,754
  • 1
  • 11
  • 20
3
votes
1 answer

How to stop DataMapper from double query when limiting columns/fields?

I'm not sure if I'm at fault here or if my approach is wrong with this. I want to fetch a user (limiting columns/fields only to name, email, id): @user = User.first(:api_key => request.env["HTTP_API_KEY"], :fields => [:id, :name, :email]) The…
ghstcode
  • 2,813
  • 1
  • 17
  • 29
3
votes
0 answers

How to use Virtus with Sequel or ROM?

I've started using DataMapper in my project, then I've found out that it is actually a frozen project. DataMapper 2.0 moved to ROM (Ruby Object Mapper), however the Property API from DataMapper was extracted to Virtus project. What I need is to keep…
Michał Fita
  • 1,113
  • 1
  • 9
  • 22
3
votes
1 answer

DataMapper Many-to-Many Delete Constraint

Let's say we have two models with a many-to-many relation: class Tag include DataMapper::Resource property :id, Serial has n, :articles, through: Resource end class Article include DataMapper::Resource property :id, Serial has n, :tags,…
user1252065
3
votes
1 answer

How to write a custom Datamapper adapter?

I am trying to write a simple Datamapper adapter that will be used to query an HTTP API. I spent quite some time trying to find some documentation, but everything seemed to be quite old (appart from a Taiwanese Ruby Conf in Chinese...). Which…
Nekosan
  • 145
  • 8
3
votes
0 answers

Integrating complex SQL queries with DataMapper

I have a fairly complicated sorting function I need to use that involves several joins and a bit of math. Because of this, there's no way to incorporate this into the standard DataMapper syntax (such User.all(:order => ...) ). Currently I have…
AlexQueue
  • 5,549
  • 4
  • 26
  • 41
3
votes
2 answers

Ruby Datamapper count not working

From irb when I do: Router.all(:email=>"blake@gmail.com") I get a list of all the routers associated with that email. But when I do: Router.count(:email=>"blake@gmail.com") I always get 0 I've also looked at this question: Ruby Datamapper…
Blake Erickson
  • 745
  • 1
  • 9
  • 27
3
votes
2 answers

How can I serialize DataMapper::Validations::ValidationErrors to_json in Sinatra?

I'm developing a RESTful API using Sinatra and DataMapper. When my models fail validation, I want to return JSON to indicate what fields were in error. DataMapper adds an 'errors' attribute to my model of type…
AnyWareFx
  • 131
  • 1
  • 6
3
votes
1 answer

Ruby Datamapper group by with max

I have a MySQL table: id int a varchar b varchar c varchar version int active bool I want to grab the max version group by a, b and c, so I have the following query to do that: select a, b, c, max(version) as version…
JVK
  • 3,520
  • 8
  • 35
  • 61
3
votes
1 answer

How do I separate finalizing into different databases in DataMapper?

Currently in my Sinatra + DataMapper app, I have: require 'data_mapper' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/main.db") DataMapper.setup(:comments, "sqlite3://#{Dir.pwd}/comments.db") class Recording include DataMapper::Resource …
Imnotanerd
  • 1,089
  • 2
  • 15
  • 29
3
votes
2 answers

Generate datamapper models from an existing database

Is it possible with datamapper to generate the models from an existing database schema? So, to do the inverse of a migration, which takes the models and generate the sql. What I want is given a database schema generate the models.
Waiting for Dev...
  • 11,486
  • 5
  • 41
  • 56
2
votes
3 answers

Determine source property of DataMapper validation errors

I’m relatively new to Ruby, Sinatra, and DataMapper, but have a question about DataMapper validation errors. I know you can see any errors that occur when attempting to save a new row to the database with DataMapper by doing something like the…
bradleygriffith
  • 889
  • 1
  • 11
  • 23
2
votes
1 answer

finding Post associated with both of two Categories in Rails 3 without custom SQL

I'm working on a Rails 3 application that has (for the sake of this question) Posts linked to multiple Categories and vice versa through has_and_belongs_to_many associations: Post < ActiveRecord::Base has_and_belongs_to_many…
1
2
3
16 17