Database part of a desktop application

Hi,

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.

What kind of database would be best for this?

Thank you.
regads,
seba

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.

Am 16.10.2012 23:24, schrieb Chad P.:

according to the purpose of the app so I can learn further about it.
said, that you’d need much more than that.

What about PStore or YAML::Store?

On Wed, Oct 17, 2012 at 01:39:21PM +0900, [email protected] wrote:

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.

Chad P. wrote in post #1080198:

On Wed, Oct 17, 2012 at 01:39:21PM +0900, [email protected] wrote:

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?

regards
seba

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.

On the other hand the yaml store opens ok.

regards,
seba

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:

snipet:

#class definition above
card = Flashcard.new(name, source, target, part_of_speech, definition,
example)

File.open(“all_cards.yml”, “a+”) {|f| YAML.dump(card, f)}

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.

Am I doing something wrong even when dumping objects?

And one last question, If I go with YAML and not YAML::Store can I
delete certain card from the storage?

regards,
seba

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.

Arlen C. wrote in post #1080420:

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.

Am 19.10.2012 23:16, schrieb Sebastjan H.:

File.open(“all_cards.yml”, “a+”) {|f| YAML.dump(card, f)}

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.

unknown wrote in post #1080513:

Am 19.10.2012 23:16, schrieb Sebastjan H.:

File.open(“all_cards.yml”, “a+”) {|f| YAML.dump(card, f)}

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
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/yaml/rdoc/YAML/Store.html
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).

Am 20.10.2012 10:26, schrieb Sebastjan H.:

unknown wrote in post #1080513:

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
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/yaml/rdoc/YAML/Store.html
only provides basic info.

Since the parent is PStore, may I just use that as a full reference?

yes

Am 20.10.2012 09:39, schrieb [email protected]:

You could iterate through them with:

f = File.open(‘all_cards.yml’)
YAML.load_documents(f) do |card|
p card
end

Correction: load_documents is deprecated,
you should use load_stream for this case, too:

YAML.load_stream(f) do |card|
p card
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs