How do I implement a database

How do I implement a database / table as a batch?


I have a state machine that needs to push / paste some filenames for different users. I would traditionally use stacks as the data structure choice, but this has to be done using a database as I have no way of maintaining the data structure between incoming web requests.

I was wondering how I can implement the stack functionality using databases.

I have to support:

  • push (filename, user): Push a filename for the user
  • pop (user): Pop the top filename for the user

EDIT :

I'm working as a prototype of an idea, so I'm using sqlite3 with Python.

Many Thanks!






Reply:


If you are wondering which database to use, it really depends on your personal preferences and what you expect from it. Since I'm only familiar with MySQL, I'll answer the other part of the question assuming MySQL:

You want to use because your table will be write intensive and with large tables the row locking of INNODB is life saving.

As far as table design goes, apparently all you need is one table:

I chose any 'id' column as the primary key is replicated in each entry of each index. So entering a primary key of (user, filename) can cause performance issues if your filenames are extremely long.

The size of your ID column depends on how big your table gets. With unsigned smallint you get 65,000 lines.

Username and filenames are varchar as they are drastically different in length I assume.

This is just one way to organize your results by when they were pasted (helpful for your POP).




If you are considering an Oracle database, consider Advanced Queuing with a last in first out (LIFO) queue pattern.

At the most basic level of the queue, a producer queues one or more messages. Each message is queued and processed once by one of the consumers. A message remains in the queue until a consumer removes it from the queue or the message expires. A producer can set a delay before the message is available for consumption and a time after which the message expires. Similarly, a consumer can wait when trying to remove a message from the queue when no message is available. An agent program or application can act as both a producer and a consumer.





We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.