datamapper

How do I tell DataMapper to use “timestamp with time zone” for DateTime properties?

我是研究僧i 提交于 2019-12-22 11:19:59
问题 By default, DataMapper creates DateTime properties of type timestamp without time zone in PostgreSQL. I'd like to change that default for my project to timestamp with time zone . How can this be done? 回答1: Just set ENV['TZ'] = 'your timezone' 回答2: just in case some jruby users pass by: you need to set ENV['TZ'] = 'your timezone' and org.joda.time.DateTimeZone.setDefault(org.joda.time.DateTimeZone.forID('your timezone')) 'UTC' works fine for me. for other timezone you might need to dig into

Displaying Error Message with Sinatra

独自空忆成欢 提交于 2019-12-22 05:07:57
问题 I'm writing a simple app that takes standard input from the user. As for the email entry, I have it verify if it is in a standard email format and then have it list the problems like this when a new instance is going to be saved: u = User.new u.email = params[:email] u.save if u.save redirect '/' else u.errors.each do |e| puts e end end I know that if it is correct it should return back to the home page. If it is wrong I want it to return to the home page as well, but I want it to return an

PHP DataMapper pattern: My class needs an instance of PDO, I want to wrap it inside a Db class

一个人想着一个人 提交于 2019-12-21 21:18:29
问题 here's what I have: class Entry { public $id; public $name; public $seoName; public $timeCreated; public function someFunction() { } } class EntryMapper { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function saveEntry(Entry &$entry) { if($entry->id){ $sql = ""; } else { $sql = "INSERT INTO tbl_entry (name, seo_name, time_created) VALUES (:name, :seo_name, :time_created)"; $stmt = $this->db->prepare($sql); $stmt->bindParam("name", $entry->name); $stmt-

Automatic logging of DataMapper queries

自闭症网瘾萝莉.ら 提交于 2019-12-20 10:32:16
问题 I am working on a simple app in Sinatra with DataMapper. I want to see the queries that DM is created for my various chained finders, etc. I have tried: DataMapper::Logger.new(STDOUT, :debug) in my configure do ... end block in an environment.rb file that loads when the app is started. I have also tried: DataMapper::Logger.new('log/my-app.log', :debug) Neither yields log statements from the app accessed either through a browser or through an irb session that requires my app. I do see the app

Installing dm-types on Windows. (Win7 x64)

北城余情 提交于 2019-12-19 03:19:22
问题 I am trying to install dm-types for DataMapper on my machine with gem install dm-types I've installed Ruby from RubyInstaller (1.9.3) and I also have the DevKit installed. (Aswell as some other gems like sinatra, haml, dm-core and bcrypt-ruby). However, when I run "gem install dm-types", this happens. C:\Users\Lev>gem install dm-types Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing dm-types: ERROR: Failed to build

Master / Slave switch in the Zend Framework application layer

泄露秘密 提交于 2019-12-18 16:10:56
问题 I am writing an application which requires the Master/Slave switch to happen inside the application layer. As it is right now, I instantiate a Zend_Db_Table object on creation of the mapper, and then setDefaultAdapter to the slave. Now inside of the base mapper classe, I have the following method: public function useWriteAdapter() { if(Zend_Db_Table_Abstract::getDefaultAdapter() != $this->_writeDb) { Zend_Db_Table_Abstract::setDefaultAdapter($this->_writeDb); $this->_tableGateway = new Zend

.NET Native GUID conversion

元气小坏坏 提交于 2019-12-17 19:32:43
问题 I have an external database that is feeding information to me. One saves their data as native GUID format and my other data source supplies standard .NET GUID format string. Is there a tidy way to convert from Native GUID to GUID Structure? Also is there any validation bit to determine if a provided value is a Native GUID or not? I can't seem to find any if there is one. The difference is as follows: typedef struct _GUID { DWORD Data1; WORD Data2; WORD Data3; BYTE Data4[8]; } GUID; Data1,

Jackson: how to serialize only annotated properties

那年仲夏 提交于 2019-12-17 18:36:57
问题 I would like to define my custom serialization strategy (which fields to include), while using Jackson. I know, that I can do it with views/filters, but it introduces very bad thing - using string-representation of field names, which automatically enables problems with auto-refactoring. How do I force Jackson into serializing only annotated properties and nothing more? 回答1: If you disable all auto-detection it should only serialize the properties that you have annotated--whether it be the

Repository and Data Mapper pattern

百般思念 提交于 2019-12-17 15:26:10
问题 After a lots of read about Repository and Data Mapper I decided to implement those patterns in a test project. Since I'm new to these I'd like to get your views about how did I implement those in a simple project. Jeremy Miller says : Do some sort of nontrivial, personal coding project where you can freely experiment with design patterns. But I don't know I did all this things right or not. Here is my project structure : As you can see there are many folders which I'm going to describe them

What is the difference between the Data Mapper, Table Data Gateway (Gateway), Data Access Object (DAO) and Repository patterns?

≯℡__Kan透↙ 提交于 2019-12-17 10:14:09
问题 I'm trying to brush up on my design pattern skills, and I'm curious what are the differences between these patterns? All of them seem like they are the same thing - encapsulate the database logic for a specific entity so the calling code has no knowledge of the underlying persistence layer. From my brief research all of them typically implement your standard CRUD methods and abstract away the database-specific details. Apart from naming conventions (e.g. CustomerMapper vs. CustomerDAO vs.