Naming a method that converts raw data into an object - data-structures

Say you have data in the format:
name=john;age=33;gender=male
What would you call a method that converts data like that into an an object / associative array?
I've been thinking about:
- unserialize_variables
- parse_variables

DeserialisePerson

Person.Unserialize?

PersonReader. Works if you change how you persist the person data in the future too.

In two steps:
ContainerType person = data.parse();
Employee employee( person["name"], person["age"], person["gender"] );

Related

How to get table name for a simple Sequel Dataset object?

Ie, given a dataset object ds = DB[:transactions].where{updated_at > 1.day.ago} - no funny joins and stuff going on - how could I fetch the table name (:transactions) ?
If you want the first table in the dataset, you can use ds.first_source.
If you want it as a string you can do:
ds.first_source_table.to_s
If you want a symbol, just omit .to_s
Based on the example provided, I would do something like this.
ds.klass.name
That will return a string with the name of your table.

Laravel Database storing only value not array

$visitorphonenumber=DB::select('select phonenumber from visitortable where email=?',[Auth::user()->email]);
$booking=new bookingmodel();
$booking->visitorphonenumber=$visitorphonenumber;
This stores the value like [{"phonenumber":"9874589608"}] in database but I want to store only the 9874589608
I will add some sugar to above answer, use like
$visitorphonenumber->first()->phonenumber;
try
$visitorphonenumber=DB::select('select phonenumber from visitortable where email=?',[Auth::user()->email]);
$singlePhoneNumber=$visitorphonenumber->first();

Codeigniter: how to convert int to string and then insert into database

i have problem with CI when insert data is integer into database.
My field is oauth_uid[varchar(250)], when i use active record insert value is 10205796940433933 into that field, it's become 1.0205796940434E+16
how to fix it!
sorry, my english is not good
This is from php, if you have a int value and you wold like to convert to make a cast to string you only need to make is
$new_v = (string) $int_value;
$data_to_insert = array(
//other values
'oauth_uid' => $new_v
);
I also happened to the same thing and the problem was that I sent GET the form and received it in Controller as POST

Compare string ID to BSON::ObjectId

I have an array of made up of type BSON::ObjectId and I want it to compare against some IDs as strings.
if my_array_of_BSON_ObjectIds.include?(#my_id_as_a_string)
# delete the item from the array
else
# add the item to the array as a BSON::ObjectId
end
This is not working as the types are different, can I turn my string into a BSON::ObjectId? If so, how?
Mongoid 2.x with 10gen's driver:
BSON::ObjectId.new('506144650ed4c08d84000001')
Mongoid 3 with moped:
Moped::BSON::ObjectId.from_string('506144650ed4c08d84000001')
Mongoid 4 (moped) / Mongoid 5/6/7 (mongo):
BSON::ObjectId.from_string('506144650ed4c08d84000001')
You can use BSON::ObjectId(#my_id_as_a_string) for representation your id as BSON::ObjectId
refs http://api.mongodb.org/ruby/current/BSON.html#ObjectId-class_method
collection.delete_one({"_id"=>BSON::ObjectId(params['id'])})
This worked for me and it deleted the record from the database successfully
There's a shorter way:
BSON::ObjectId("id_here")
but for your case it would be easier to simply map the objects to ids before the comparison:
if my_array_of_BSON_ObjectIds..map(&:to_s).include?(#my_id_as_a_string)

Question about fetching only the rows of a table which has a concrete value in a concrete field using Doctrine 1.0

is there anyway to fetch only the rows of a table which has a concrete
value in a concrete field.
For example:
$24_people = $table->getFieldAndValue('age', 24);
I now i can do it with a query, but wouldn't you find useful this kind
of functions? or maybe is no possible or is not convenient because some
reason ?
Regards
Javi
You mean something like this:
$table->createQuery()->where('age = ?', 24);
or:
$table->findAllByAge(24);
?
Yes.
$24_people = Doctrine::getTable('People')->findOneByAge(24);
See Doctrine magic methods.
http://www.symfony-project.org/doctrine/1_2/en/06-Working-With-Data

Resources