Hi guys.
I've stroked your egos a lot personally, but let me just do it
publicly: your database lets me do what I'm best at (code JavaScript)
and ignore the things I'm not the best at (control and manage
databases).
Yet as I spoke to Brent about yesterday, I realized posting this up
for discussion, given I'm not a data or database guru, might speed up
my process of sorting things out. It's a multi-part post where I'll
try to make each problem I'm facing discreet.
Background
I'm making a multi-language flashcard system. I'm not recreating
wiktionary. I'm not trying to do what language learning systems do.
Personally, I want a system that I can use to build my vocabulary
(always my weakness) across multiple languages. My first focus is
Engish-German-Spanish, but eventually it would be fun to open up the
matrix of language mappings to all of the languages found in the ISO
693-2.
Before I knew about you guys, I was going to store everything in XML,
described by the XSD located at
http://jeremyosborne.com/ns/phraseMatrix/phraseMatrix.xsd.
You can probably imagine the giant, single table mindset I'm in if you
have a look at that.
The communication to the NextDB backend from my flashcards is insanely
simple and as I want to expand the app to be something useful, I ran
into the following. Given what I said above, I have been working with
a single table in NextDB. It's not something I would normally do, but
I thought a single table would help me simplify in this case.
Problem #1 - Searching dynamic columns with NextQuery
My first table looks like this (I'm going to post and pray the
formatting sticks):
id | eng | deu
1 | green | gruen
If the formatting doesn't stick, know that the top row are the column
names and pipes delimit.
Perfect! Two columns, nice and easy to manage. Now I want to expand to
the following:
id | eng | deu | spa
1 | green | gruen | verde
For reading, this is not a problem. I can use the simple mechanism of
retrieving a random card by id, which is how the flash cards work:
find the total number of rows in the data table; and grab a random
card from minId to maxId; retrieve from the data results object the
language that should display on the front of the card (eng in my case)
and the content that should display on the back of the card (which
could now be german or spanish).
As I move into finding a way for users to update data in the database,
I'm attempting to find the best method of querying columns dynamically
at runtime.
I believe this is where my big table approach will fail here.
In NextQuery I could not find a way to dynamically choose the column
name that I want to search for. If I constrain searching to 2 columns,
and my table has N columns, I believe I'm going to need to create
approximately N! queries in NextQuery if they look like the following:
NAME=get_phrase_eng_deu;
ROW phrase FROM PHRASEENTRIES;
WHERE (TEXT eng, TEXT deu){
phrase.eng = ${eng}
AND
phrase.deu = ${deu}
}
Would you gentlemen every be up to adding either a form of set
constraints or dynamic column selection to the variable?
One idea, using [] to denote an array of N number of items:
NAME=get_phrase_eng_deu;
ROW phrase FROM PHRASEENTRIES;
WHERE (TEXT phrase1, TEXT[] columns){
for ( i in ${columns} ) {
phrase.${columns}[i] = ${phrase1}
}
}
Another idea:
NAME=get_phrase_eng_deu;
ROW phrase FROM PHRASEENTRIES;
WHERE (TEXT phrase, TEXT column){
phrase.${column} = ${phrase}
}
Thanks for reading and for any thoughts and comments. I have another
related but different enough conundrum that I'll post in a separate
topic.