I’ve tried to find a solution on the forum and google prior to opening a
new topic, but I am still not clear on this so here goes.
I would like to make a desktop application for flashcard learning. The
biggest question for me right now is which approach to take for the
database part of the application. I have no experience with creating and
using databases in ruby so I just need to know which option to choose
according to the purpose of the app so I can learn further about it.
As I said, it would be an application for creating flashcards for
learning a foreign language. Each card would have some attributes and of
course there would be the usual flashcard logic to the whole app.
On Wed, Oct 17, 2012 at 05:28:39AM +0900, Sebastjan H. wrote:
As I said, it would be an application for creating flashcards for
learning a foreign language. Each card would have some attributes and of
course there would be the usual flashcard logic to the whole app.
What kind of database would be best for this?
Depending on the volume of data you wish to store, something simple and
hierarchical like YAML might serve well. If you need a bit more than
that, you might look into SQLite. It seems unlikely, from what you’ve
said, that you’d need much more than that.
using databases in ruby so I just need to know which option to choose
that, you might look into SQLite. It seems unlikely, from what you’ve
said, that you’d need much more than that.
using databases in ruby so I just need to know which option to choose
that, you might look into SQLite. It seems unlikely, from what you’ve
said, that you’d need much more than that.
What about PStore or YAML::Store?
Those should work just fine.
Thank you all for suggestions, I’ve tried PStore and YAML::Store and
they work perfectly for my purpose. Is there any practical reason why
choose one over the other? And what about performance related to the
size of the database?
Thank you all for suggestions, I’ve tried PStore and YAML::Store and
they work perfectly for my purpose. Is there any practical reason why
choose one over the other? And what about performance related to the
size of the database?
There is one thing that’s odd though. If I want to manually edit or view
the .pstore object, the editor (I use gedit) reports the invalid
character error. There are those strange characters inside the file. The
coding is UTF-8.
There is one thing that’s odd though. If I want to manually edit or view
the .pstore object, the editor (I use gedit) reports the invalid
character error. There are those strange characters inside the file. The
coding is UTF-8.
PStore databases are not intended to be human-editable; their contents
are binary, so you can’t use GEdit, for instance, to edit them.
I need some further advise. I would go with either YAML or YAML::Store
because then I’d get the manually editable file storage. However, I am
searching the net for some examples but some have puzzled me even more
(some use YAML.dump, others to_yaml and so on).
So I turned back to the pickaxe, which is a bit scarce for me regarding
the YAML and I managed to get the objects stored in the .yml file, but I
am not sure if I did it the right way to suite my purpose:
On Fri, Oct 19, 2012 at 02:00:39PM +0900, Sebastjan H. wrote:
Thank you all for suggestions, I’ve tried PStore and YAML::Store and
they work perfectly for my purpose. Is there any practical reason why
choose one over the other? And what about performance related to the
size of the database?
PStore uses the Marshal format for storing data. YAML::Store uses the
YAML format. The difference is that the Marshal format is binary (as
opposed to text), and the YAML format is a hierarchical data structure
format represented in plain text (and is thus human readable and
writable). I would probably use YAML::STORE rather than PStore unless I
had a specific reason to do otherwise for that reason; I consider human
readability a positive feature, in part for purposes of making it easy
to
create more tools that are compatible with whatever software you’re
writing. Plain text is essentially the one and only universal data
format, after all.
Performance for large databases depends on your definition of “large”.
I
would recommend not worrying about it too much unless you actually
measure performance and find that it is unacceptable. I don’t strictly
agree that “premature optimization is the root of all evil”, but it sure
is at the root of a lot of evil in programming.
There is one thing that’s odd though. If I want to manually edit or view
the .pstore object, the editor (I use gedit) reports the invalid
character error. There are those strange characters inside the file. The
coding is UTF-8.
PStore databases are not intended to be human-editable; their contents
are binary, so you can’t use GEdit, for instance, to edit them.
Thank you. I wasn’t intending on editing them, I was just curious about
the file structure, that’s why I opened it.
This appends object after object. Here’s the problem. How can I then
access and display certain or all cards after loading the file:
card_file = YAML.load_file(“all_cards.yml”)
I’ve tried putsing the card_file with different parameters but I always
get back the name of the first objec tin the storage.
By appending, you end up with several YAML documents (or objects)
in your file.
You could iterate through them with:
f = File.open(‘all_cards.yml’)
YAML.load_documents(f) do |card|
p card
end
Or you could read them all at once with:
cards = nil
File.open(‘all_cards.yml’) do |f|
cards = YAML.load_stream(f)
end
p cards
And one last question, If I go with YAML and not YAML::Store can I
delete certain card from the storage?
Read in all the cards and overwrite your YAML file, leaving out the
card you want to delete.
Thank you. I think I’ll also look into the YAML::Store a bit more. Where
would I find a complete reference for it? Ruby-doc at
only provides basic info.
Since the parent is PStore, may I just use that as a full reference?
I think the confusing part in all this is my perception of the storage
files related to these functionalities and their manipulation (storing
and loading of objects).
Thank you. I think I’ll also look into the YAML::Store a bit more. Where
would I find a complete reference for it? Ruby-doc at Class: YAML::Store (Ruby 1.9.3)
only provides basic info.
Since the parent is PStore, may I just use that as a full reference?