all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Tim Landscheidt <tim@tim-landscheidt.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Interacting with PostgreSQL
Date: Wed, 25 Nov 2020 17:25:56 +0300	[thread overview]
Message-ID: <X75pdIYyxtOKWK1U@protected.rcdrun.com> (raw)
In-Reply-To: <87blflvi1j.fsf@passepartout.tim-landscheidt.de>

* Tim Landscheidt <tim@tim-landscheidt.de> [2020-11-25 13:38]:
> The problem is that you do not need to consciously use auto-
> commit mode, but that psql automatically reverts to it when
> you rollback or commit a transaction:
> 
> | tim=> BEGIN WORK;
> | BEGIN
> | tim=> INSERT INTO t (ID) VALUES (1);
> | INSERT 0 1
> | tim=> ROLLBACK WORK;
> | ROLLBACK
> | tim=> INSERT INTO t (ID) VALUES (1);
> | INSERT 0 1
> | tim=> -- The row has been committed.

I understand. I always used it manually and will rather continue. Just
observing how you do it.

> > I am interested in your work.
> 
> > What do you store in the database?
> 
> > Do you interact through Emacs with it?
> 
> Yes, that was the point of my question :-).  I use Postgre-
> SQL to store most data that fits a relational model and (for
> a huge part) use Emacs to interact with it.  I also use a
> number of Perl scripts for daily consistency checks and
> other Perl/Python scripts where either the input/output will
> be part of a pipeline or there is a modal UI that I do not
> (yet) have the motivation to rewrite in Emacs Lisp (e. g.,
> playing a podcast in the background and "afterwards" asking
> the user whether the podcast should be marked as "heard" and
> then update the database accordingly before archiving/delet-
> ing the podcast file).

That is some type of logging or recording, I understand.

Any time I need some structured and relational data I use
PostgreSQL. For example to insert geographic locations of interests
that are helpful to other people or coordinates of lands. When
coordinates are in the database then I can invoke map downloads with
nicely shown lands on the geographic map.

In general I use database for everything including for sorting files
by using database where program decides where files are sorted not me,
for quick retrieval of files where program decides it, for SMS record,
phone calls, notes, project planning, Website Revision System,
variables for the WRS.

It helps in preparing translations, I can just write some words into
database then I run program that fetches automatic translations and
translates it before human makes the review of it.

Also for website forms, like all those small pieces of HTML like text
inputs, check boxes and similar. When there is a lot of work that
becomes simple reuse without much copy/paste or looking into files.

Then for invoices, for reporting and records of all kinds, reminders,
real estate agency, opportunities, market pricing, statistics, just
for anything that requires structure and relations.

Do you use any kind of revision system?

I have made recently my own revision system, you can see the simple
table below, and `hyperscope-vc' that fetches values and inserts into
the "version control" table.

Then function like `hlink-edit-org' with `hyperscope-vc' before the
update makes sure that information first get recorded in the version
control table. I could as well record all updates that I do through
Emacs and it could be possible to make triggers as well, but I like it
this way now.

If you know other ways of version control, let me know.

(defun hlink-edit-org (id)
  (let* ((blob (hlink-description-value id))
	 (blob (if blob blob  ""))
	 (buffer-name (format "HyperScope Editing ID: %d" id))
	 (new-blob (read-from-buffer blob buffer-name 'org-mode)))
    (hyperscope-vc "hlinks" "hlinks_description" id)
    (rcd-db-update-entry "hlinks" "hlinks_description" "text" id new-blob *hs*)))

(defun hyperscope-vc (table column id &optional description)
  "Simple version system."
  (let* ((value (rcd-db-get-entry table column id *hs*))
	 (value (sql-escape-string value)) ;; TODO only text supported for now
	 (description (if description (sql-escape-string description) "NULL"))
	 (sql (format "INSERT INTO vc (vc_table, 
                                      vc_column, 
                                      vc_tableid, 
                                      vc_value, 
                                      vc_description) VALUES ('%s', '%s', %s, %s, %s)
                         RETURNING vc_id"
		      table column id value description))
	 (id (rcd-sql sql *hs*)))
    (if id id nil)))

CREATE TABLE vc (
vc_id SERIAL NOT NULL PRIMARY KEY,
vc_datecreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
vc_datemodified TIMESTAMP,
vc_usercreated TEXT NOT NULL DEFAULT current_user,
vc_usermodified TEXT NOT NULL DEFAULT current_user,
vc_table TEXT NOT NULL,
vc_column TEXT NOT NULL,
vc_tableid INT4 NOT NULL,
vc_value TEXT 
);



  reply	other threads:[~2020-11-25 14:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-21 23:51 Interacting with PostgreSQL Tim Landscheidt
2020-11-22  1:33 ` Jean Louis
2020-11-24 23:14   ` Tim Landscheidt
2020-11-25  4:18     ` Jean Louis
2020-11-25 10:37       ` Tim Landscheidt
2020-11-25 14:25         ` Jean Louis [this message]
2020-11-25 17:08           ` Tim Landscheidt
2020-11-27  1:40             ` Jean Louis
2020-11-30  3:12               ` Tim Landscheidt
2020-11-30  9:12                 ` Jean Louis
2020-11-22 21:33 ` Marcin Borkowski
2020-11-24 20:42   ` Tim Landscheidt
2020-11-27  2:01   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X75pdIYyxtOKWK1U@protected.rcdrun.com \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tim@tim-landscheidt.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.