Is it possible to create a Javascript database?

Asked

Viewed 2,122 times

6

How to create a simple database without using a server?
I believe the answer would be no, but check the following:

  • I’m at work and I don’t have access to the databases or even the servers. This way I can work only on the local network and shared folders.

  • I can not connect USB to the machine and also I am not computer admin.

  • The information I need to store is few and simple, without the need to use a database.

  • The people who will make changes or inclusions in this information are a working team, with no possibility of simultaneous editions.
  • Not everyone can edit the code through the editor, because of this looking for other ways to include information on the page.

The idea would be to create a simple form in IE8, because I only have access to it.

  • HTML : It has two presses one for insertion and another that receives the information
  • Knob: "Save" this runs a documento1.js which identifies the entered fields and saves the fields in any extension.

What do I have:

  • I can store by Javascript the information typed in a file .js among others.
  • I can save the file as for example documento2.js, giving a var to each input field, so I can identify the fields later.
  • The documento2.js click on head HTML, so any update to the document giving F5 HTML access.

What I lack:
I need the form that will return results to automatically recognize the fields in the documento2.js.

<td name="recebe" id="Campo01">
(aqui o codigo que preciso para trazer um resultado que esteja no documento2.js com a identificação "Campo01") 
</td>

*If necessary I could change the file extension to save the information, I just need HTML to reload this file on head and populate some fields according to the data of this file.

Or is there a less complicated solution to work saving information off?

  • 2

    I think creating an XML file would be the right thing to do

  • 1

    Via HTML5 you have Local Storage at your disposal: http://www.html5rocks.com/en/features/storage

  • 1

    You need this information to be portable? (i.e. that you can transport them from the computer A pro B) if the answer is nay, you can use something like Local Storage, Indexed DB or Web SQL. If it is yes, maybe it is better to use an HTTP mini-server that you can load on a USB stick, for example (there are several language and technology options to implement this).

  • Onosendai: I won’t be able to use Google Chrome, as not everyone who views it will. mgibsonbr: Yes I need that the information contained in the page can be viewed on other computers on the same network.

  • 1

    @Cleverson The Local Storage is supported on virtually every browser, including IE8. But that’s irrelevant, since what you want is a little more complicated... I don’t know if I can answer this question in this format, because it’s a little too wide, but I’ll try.

  • Couldn’t you make your machine a web server with a database? (of course, this only makes sense if there is no restriction on this: some kind of computer policy).

  • Or could use a Sqlite would not be practical ?

  • Maybe I’m talking nonsense but what if I use a SQLITE database file with Noje.JS? As far as I could see is how the blog platform Ghost opera.

  • You have to be careful with Dead-Lock, this can occur every time a user has locked a record in a table and your next step will be to lock a record in a table related to the first, but if this record is locked by another user, the first user will be paralyzed, because, will be waiting for the second user to release the record in use, so that then can lock it and continue its task.

Show 4 more comments

3 answers

9

It is inadvisable to use the file system itself on a network drive for data that will potentially be changed by two or more people concurrently. The ideal is to use a mini webserver for this. For this solution to be applicable, there is a prerequisite however:

Does your company’s firewall allow one computer to access another via port 80? (or another unused port)

If the answer is "yes", here’s what I suggest:

  • Use a lightweight, portable database such as Sqlite. Use this database as a client-server is complicated, and in your case does not justify the effort. So a single process (the mini webserver) should connect to that bank, does not free access to it via network unit. In the end, the entire bank will be contained in a single file, which you can move to another place without problems when needed, make backups, etc.
  • Develop your application in a portable mini-webserver that is simple to install and configure. What technology to use, then depends on your expertise, but by way of example I will mention two that I have already used in practice, successfully:
    • Jaminid (Java Mini Daemon), using HSQLDB (pure Java database, with option to keep the tables in memory). This project is very dead (not updated since 2006) but should still work. Good if you have experience with Java, and access to a JVM in your environment (because nothing else is necessary to install).
    • Django. If you have Python in your environment, you can run Django in simplified mode without the need for an external webserver. It integrates well with Sqlite.
  • Put your mini-webserver to work on your computer, and have the other computers on the network access it through your IP and custom port if necessary. So everyone will read and write in the same bank, no competition problems.

The technologies I mentioned are two that I have already used personally and I confirm that they are feasible, but there are many others (like Node.js, for example). Probably many even easier to use. Look for "Portable web server" and you will find many options (example, example).

  • This answer shows an excellent way to address your problem. Databases like Sqlite, H2 and HSQLDB will solve your problem. Another option is the Firebird database (Interbase Fork, when it was open-source).

  • Really you are correct, but still I look for an alternative way, using only fixed files in fixed locations.

4


Short answer: No!

Elaborating a little more: Depends of your needs. A DBMS is a powerful tool to persist your data. Therefore the name DATABASE, your data is saved and protected and when you need them they can be accessed quickly and effectively. Saving data to files even works if you don’t have a lot of data or complexity in the information.

Javascript is something that is running in the browser, so all information stays in the client unless you upload some kind of data. In real world applications there is not much point in harvesting user data that you, on the server side, will not have access to.

Finally, there are "cloud" technologies that might be useful to you and take a good look at Node.js.

Edit 2 I still don’t fully understand why you want to save information offline but this Puchdb quoted in the comment seems interesting (I didn’t know it) so that you can read "on top" it works synchronizing data typed offline when the page comes back online. But then he seems to need Counchdb (which in turn runs on an apache server) but is worth a look when I have more time.

As for your need to store small pieces of data offline maybe you should use cookies! But there goes a path I don’t usually tread (my business is more dealing with large online enterprise applications)

  • 3

    There is controversy: http://pouchdb.com/

  • I did the editing. Really the idea is to save a file with the client data so that the html can reload this file in some predetermined fields.

  • @Gypsy Morrison Mendez +1 for mentioning Pouchdb but he doesn’t need an Apache server running Counchdb?

  • @No, he’s inspired by Couch. It’s just one example. There are many others.

0

Dear, after a few hours I managed to develop a code let’s say simple in javascript.

I don’t know if it’s really functional, but it matches what I need.

1 - It works like this: HTML has an input that receives what the client type, and a "p" that will receive the information later.

2 - Javascript captures what the client types and with a save button creates an example.js file with an "x" function and the information I need there, this file is stored in the network folder.

3 - HTML opens the example.js file by HEAD and the "x" function in onload by BODY, the "x" function causes "p" to receive the information stored in the example.js.

I’ll edit it later to make it more understandable, because I have to leave.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.