datamapper

Is parsing a json naively into a Python class or struct secure?

房东的猫 提交于 2019-12-05 04:33:57
Some background first: I have a few rather simple data structures which are persisted as json files on disk. These json files are shared between applications of different languages and different environments (like web frontend and data manipulation tools). For each of the files I want to create a Python "POPO" (Plain Old Python Object), and a corresponding data mapper class for each item should implement some simple CRUD like behavior (e.g. save will serialize the class and store as json file on disk). I think a simple mapper (which only knows about basic types) will work. However, I'm

PHP datamapper - why use them for non-collection objects?

大憨熊 提交于 2019-12-04 17:03:01
Perhaps this is a question with a trivial answer but nevertheless it is driving me nuts for a couple of days so i would like to hear an answer. I'm recently looking up a lot of information related to building a custom datamapper for my own project (and not using an ORM) and read several thread on stackoverflow or other websites. It seems very convincing to me to have AuthorCollection objects, which are basically only a container of Author instances or BookCollection objects, which hold multiple Book instances. But why would one need a mapper for the single Author object? All fetch criterias i

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

萝らか妹 提交于 2019-12-04 14:51:03
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->bindParam("seo_name", $entry->seoName); $stmt->bindParam("time_created", $entry->timeCreated); $stmt-

DataMapper has n through Resource DELETE (Remove from association) not working

ぐ巨炮叔叔 提交于 2019-12-04 14:19:48
I'm have this two classes, class User include DataMapper::Resource property :id, Serial property :name, String has n :posts, :through => Resource end class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text has n :users, :through => Resource end So once I have a new post like: Post.new(:title => "Hello World", :body = "Hi there").save I'm having serious problems to add and remove from the association, like: User.first.posts << Post.first #why do I have to save this as oppose from AR? (User.first.posts << Post.first).save #this just works if

How to extend DataMapper::Resource with custom method

心不动则不痛 提交于 2019-12-04 13:14:26
I have following code: module DataMapper module Resource @@page_size = 25 attr_accessor :current_page attr_accessor :next_page attr_accessor :prev_page def first_page? @prev_page end def last_page? @next_page end def self.paginate(page) if(page && page.to_i > 0) @current_page = page.to_i - 1 else @current_page = 0 end entites = self.all(:offset => @current_page * @@page_size, :limit => @@page_size + 1) if @current_page > 0 @prev_page = @current_page end if entites.size == @@page_size + 1 entites.pop @next_page = (@current_page || 1) + 2 end entites end end end Then I have call of #paginate:

Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter

*爱你&永不变心* 提交于 2019-12-04 13:06:44
问题 For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself. I built a default facebook app. The Gemfile: source :gemcutter gem "foreman" gem "sinatra" gem "mogli" gem "json" gem "httparty" gem "thin" gem "data_mapper" gem "heroku" group :production do gem "pg" gem "dm-postgres-adapter" end group :development, :test do gem "sqlite3" gem "dm-sqlite-adapter" end Datamapper setup

Simple Search With Datamapper and Sinatra

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 11:47:59
I'm fairly new to Ruby and backend development in general. That being said I'm trying to create a simple search form. I'm using Sinatra as the framework and Datamapper as my ORM. What is the best way to do this? Below is my schema I would like the search action to search both the tile and category. require 'sinatra' require 'datamapper' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cal.db") class Event include DataMapper::Resource property :id, Serial property :title, String property :text, Text property :contact_name, String property :contact_email, String property :location, String

Some uncertainty with implementing the 3 structure Model (Domain object, data mapper and service)

末鹿安然 提交于 2019-12-04 10:51:31
As the heading suggests I am having some small problems while implementing the 3 structure Model (Domain object, data mapper and service). In the past when someone was registering on my site I would simply do $user->register($firstName, $lastName, $emailAddress, $username...); and that method would run in steps like this 1. Check if the form sent was valid. 2. Check if all the required fields were filled. 3. Check the if the lengths of strings were valid and the range of integers etc. 4. Check if the input is in the correct format (regex). 5. Check if the username is already taken and if the

Use DataMapper instead of ActiveRecord [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:08:10
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . DataMapper idea is definitely better than ActiveRecord. It has one API for a variety of data stores, including RDBMS and NoSQL stores. DataMapper is much smarter then ActiveRecord. It has "Strategic Eager Loading". This feature single

How is the Data Mapper pattern different from the Repository Pattern?

回眸只為那壹抹淺笑 提交于 2019-12-04 07:39:47
问题 I found two patterns which appear to have the same goal - what is the difference? http://martinfowler.com/eaaCatalog/dataMapper.html http://martinfowler.com/eaaCatalog/repository.html 回答1: [the Repository is] another layer of abstraction over the mapping layer where query construction code is concentrated. The DataMapper ensures the DB side of the fence doesn't need to know about the specifics of your business logic and how the data is kept in memory by your business objects and your business