📜 ⬆️ ⬇️

Search, find and do not blow off

Friends, we want to tell you about our service Shdmka.rf and some details of its manufacture. Under the cut article about balloons, CouchDB, Lisp and a couple of pictures.
KDPV
Holidays are coming, and perhaps one of you will find an idea for a gift.

Many have seen clowns making dogs out of balloons. Very cute and very funny. Someone, perhaps, even tried to turn the balls on their own.

Today, an incredible amount of beautiful pieces is made of balloons. Festivals and simply interesting events are held.

We made a website-catalog of aerodesigners (and gradually designers began to be called that way), and the main thing on the site is photos of the works of aerodesigners. We differ from other directory sites by having a notebook, which a simple user fills and sends to the designer in his city / region. The designer, however, can also send a letter to the client with a filled pad.
')


I'll tell you about the technical component of the site, because during the development process several interesting things were found, or poorly described in the documentation, or this description had to be collected bit by bit in the forums.

Lisp


The site is written in Common Lisp (in the SBCL implementation). The choice of language is due to the convenience of coding and a large number of libraries . Only two libraries were adjusted for their needs, and very slightly, the rest was working out of the box.

The site code is compiled directly into the machine code, respectively, the site performance is high. I want to believe that this statement will stand the test of habrae :)

Couchdb


CouchDB is used as data storage. It contains photos and miniatures for them, as well as information about users.

CouchDB includes a rather convenient Futon data management environment, which has one drawback - all the JS code that is used to manage the database (views, list functions, etc.) is serialized to a string and is almost impossible to edit in the environment itself. .

The couchapp utility is used to solve this problem.

Couchapp

This is a small python utility that allows you to create stand-alone (standalone) applications on CouchDB. The template utility generates application code and, most importantly, allows one command to load the application into CouchDB. At the same time, the application itself has a tree structure in the file system, where in different folders there is a code of different elements, for example, views or auxiliary code. In a normal human form.

In addition, the utility allows you to add different elements of couchapp applications as they are developed - views, lists, etc.

For example:

couchapp generate view check-user 

Here, check-user is the name of the generated view. The utility creates the views / check-user directory, which will contain templates for map and reduce functions.

Update-functions

Since the data is never overwritten in CouchDB, but only added to the database, a very important element of the work is the availability of a document revision. Almost any reference to a recorded document requires knowledge of the revision of the document. This is not always convenient.

CouchDB has update functions (update functions) that allow you to manipulate documents on the server side (without downloading them to the client), without knowing their revision. The documentation describes this point in a rather modest way; at the same time, the update functions allow you to do interesting things:

 function(doc, req) { if (!doc) { doc = { _id: req.id, type: 'idGenerator', count: 0 }; } doc.count++; return [doc, '"' + doc.count + '"']; } 

The given code fragment for each function call increases the document count field. Thus, a sequential number generator on CouchDB is implemented.
The function call, by the way, is as follows:

 curl -X POST http://localhost:5984/database/_design/view-doc/_update/generateOrderNo/counterDoc 

Here the view-doc is the design document in the database database, generateOrderNo - update function, counterDoc - the document in the database database.

Calling the above function, we each time increment the field in the document and immediately get the value of this number. Analog field with auto increment for SQL.

CouchApp, however, does not know how to generate update functions, however, if you manually create the updates directory and put into it the function of the above content, the application is quietly loaded into CouchDB.

Code substitution

In CouchDB, there is no possibility in the functions of the representations to use any kind of library code. This problem CouchApp solves very, in my opinion, elegantly.

You can specify in the code map-function (or reduce-function) construction

 function (doc) { ... // !code vendor/myapp/common.js ... } 

and in the place in the code where this line occurs, the contents of the common.js file located in the corresponding application folder will be inserted. It may not be the most beautiful solution, but it allows you to write common code once.

Framework


The Ink framework was chosen as the basis for the interface. It has an interesting internal structure and advanced functionality. In addition, the framework is developing quite quickly.

Conclusion


In general, when you want a holiday, think about the balloons. Especially, on Friday Thursday evening before the holiday.

Well, aerodesigners who can arrange this holiday can be found on our website. On the main page there is a link to a page with designers from your region. If it turns out that there is no one there, you can click the “I want it to be!” Button and we will invite aerodesigners from your cities referring to your interest.

In the picture to attract the attention of FreeBSD mascot, made of balloons, the CouchDB logo and one of the Lisp logos, made on coffee.



Finally, a few pre-holiday links:

FreeBSD ball mascot
Geeklatte.com, IT pictures on coffee

Thanks for attention!

Criticism and suggestions are welcome.

Source: https://habr.com/ru/post/257087/


All Articles