This serves as example on how to embed PostgreSQL queries and its results as Emacs Lisp within plain text. This example uses the RCD Template Interpolation System for Emacs.

Let us say we wish to get number of people in the PostgreSQL database. The database is not located online, it is not on any online server. It is offline as that is one of principles we use in business. Keep your data offline.

Following SQL query would yield with some result, like a number:

SELECT count(1) FROM people;

In the next step I may wish to embed the number of people in the text. Then I would need to use something like this before pre-processing wihth RCD Template Interpolation System:

Number of people in the database is:
[ (rcd-sql-first "SELECT count(1) FROM people;" cf-db) ]

And if delimiters are brackets such as [ and ] it will evaluate to following:

Number of people in the database is:
225205.0

And in the following section the RCD Template Interpolation System for Emacs will be used to provide some basic database statistics.

Sample Database Statistics

Date of report:

2021-05-03

Number of people:

225205.0

Number of accounts:

16098.0

Date of first mailing ever sent:

2013-10-18

Date of last mailing ever sent:

2021-05-03

Total number of messages sent:

669555.0

Total number of SMS sent and received:

25161.0

Source of this page:

The source of this page may be shown by using the same technique of template interpolation and embedded Emacs Lisp. It pulls itself straight from the database and adds space before "----" as not to cause problems with the final markup.

You can get the point how this page has been generated and how Emacs Lisp and PostgreSQL can be embedded by using the RCD Template Interpolation System for Emacs.

Hyperlinks may be also embedded as if the name of hyperlink ever changes, then the name would be updated in each page that uses such hyperlinks, including the URL if it ever changes. Good URLs should never change.

:source-highlighter: rouge

This serves as example on how to embed PostgreSQL queries and its
results as Emacs Lisp within plain text. This example uses
the ⟦ (hyperscope-hyperlink 37133 40) ⟧.

Let us say we wish to get number of people in the PostgreSQL
database. The database is not located online, it is not on any online
server. It is offline as that is one of principles we use in
business. Keep your data offline.

Following SQL query would yield with some result, like a number:

[source,sql]
 ----
SELECT count(1) FROM people;
 ----

In the next step I may wish to embed the number of people in the
text. Then I would need to use something like this before
pre-processing wihth *RCD Template Interpolation System*:

 ----
Number of people in the database is:
[ (rcd-sql-first "SELECT count(1) FROM people;" cf-db) ]
 ----

And if delimiters are brackets such as [ and ] it will evaluate to
following:
 ----
Number of people in the database is:
⟦ (rcd-sql-first "SELECT count(1) FROM people;" cf-db) ⟧
 ----

And in the following section the ⟦ (hyperscope-hyperlink 37133 40) ⟧
will be used to provide some basic database statistics.

== Sample Database Statistics

[cols=2*]
|===
|Date of report:
| ⟦ (rcd-iso-date) ⟧

|Number of people:
|⟦ (rcd-sql-first "SELECT count(1) FROM people;" cf-db) ⟧

|Number of accounts:
|⟦ (rcd-sql-first "SELECT count(1) FROM accounts;" cf-db) ⟧

|Date of first mailing ever sent:
|⟦ (rcd-sql-first "SELECT mailings_datecreated::date FROM mailings
                         ORDER BY mailings_datecreated LIMIT 1" cf-db) ⟧

|Date of last mailing ever sent:
| ⟦ (rcd-sql-first "SELECT mailings_datecreated::date FROM mailings
                         ORDER BY mailings_datecreated DESC LIMIT 1" cf-db) ⟧

|Total number of messages sent:
| ⟦ (rcd-sql-first "SELECT count(1) FROM mailings;" cf-db) ⟧

|Total number of SMS sent and received:
| ⟦ (rcd-sql-first "SELECT count(1) FROM sms;" cf-db) ⟧
|===

=== Source of this page:

The source of this page may be shown by using the same technique of
template interpolation and embedded Emacs Lisp. It pulls itself
straight from the database and adds space before "----" as not to
cause problems with the final markup.

You can get the point how this page has been generated and how Emacs
Lisp and PostgreSQL can be embedded by using the ⟦ (hyperscope-hyperlink
37133 40) ⟧.

Hyperlinks may be also embedded as if the name of hyperlink ever
changes, then the name would be updated in each page that uses such
hyperlinks, including the URL if it ever changes. Good URLs should
never change.

[source,asciidoc]
 ----
⟦ (string-replace "\n----" "\n ----" (rcd-db-get-entry "hlinks" "hlinks_text" 37136 cf-db)) ⟧
 ----
=== Comments are welcome

You may easily contact me by email to my current web comment email
address: ⟦ mailto-bugs ⟧.

Comments are welcome

You may easily contact me by email to my current web comment email address: 2021-05-02@gnu.support.

GNU Free Documentation License

Copyright © 2021-05-02 10:25:39.139945+02 by Jean Marc Louis. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License"