SQL database + Naarvin: read any ledger with a read-only login

Connect any accounting system through its PostgreSQL, MySQL or SQL Server database: one read-only query per table, over an encrypted connection, on a schedule.

3 min read
In short

When a system has no connector, Naarvin can read its books straight from the database: PostgreSQL, MySQL or MariaDB, or Microsoft SQL Server, over an encrypted connection and as a user that can only read. You write one SELECT per table of Naarvin's standard dataset, so any schema maps without code, and Naarvin never writes to the database.

How does the SQL connection work?

You give Naarvin queries, not table access. Each query returns rows with the same columns as the Excel and CSV import templates, using the English or Arabic column names or the column keys such as account_code. Naarvin runs them on the schedule you set and loads the rows exactly as it loads an import.

The queries a SQL connection can run
QueryNeededBrings
AccountsYesThe chart of accounts
Journal linesYesEvery posted line, with date, account, debit and credit
Customer invoices and vendor billsNoOpen items, with credit notes
Invoice and bill linesNoLine amounts with VAT category, rate and tax, for the VAT return and e-invoicing checks
Customer and vendor paymentsNoWhat is still on account, and the invoice each payment settles
Customers and vendorsNoNames, VAT numbers, contacts, country and terms
Exchange ratesNoDated rates
CompaniesNoCode, name, currency and country, when the database holds several companies

How is the database kept safe?

  • The connection is encrypted with TLS, and the certificate is checked against the server name.
  • You create a database user that can only SELECT from the tables your queries use.
  • Each query runs inside a read-only transaction where the database has one.
  • Naarvin also refuses any query that is not a single SELECT or WITH statement, or that contains words that change data, run procedures or reach outside the database.
  • The password is encrypted when saved and never shown again, and the AI never sees it.
  • The server must have a public address. Naarvin refuses private and local addresses, so allow its address through your firewall.

Does every sync read everything?

Only if you want it to. Put :since in a journal or invoice query, for example WHERE modified >= :since, and later syncs read only what changed since the last one. Without it, each sync reads everything, and entries the query no longer returns are marked deleted. If a sync would remove more than half of what is loaded, it removes nothing and warns you instead. Rows that fail the import checks are left out and listed as sync warnings.

Schedules run every 15 or 30 minutes, every 1 to 12 hours, daily or weekly in your time zone, or only by hand.

Can one database hold several companies?

Yes. Add a companies query and a company code column to the others, and each company links to its own company in Naarvin with the same currency. A database with one company can leave the column out and name the company's code, currency and country on the connection. Rows in another currency carry their own exchange rate, as in the import templates.

How do you connect a database?

  1. Create a read-only userGrant SELECT on the tables your queries use, and nothing else.
  2. Write the queriesStart with accounts and journal lines, aliasing your columns to the template keys, for example SELECT code AS account_code.
  3. Add the connectionChoose the database type and enter the server, port, database name, the queries and the user. Naarvin tests the connection and lists the companies it finds.
  4. Run the first sync and check itCompare the trial balance in Naarvin with your system's own, read the warnings, then add the optional queries.

Questions people ask

Can Naarvin change anything in our database?

No. The user should only be able to read, each query runs read-only where the database supports it, and Naarvin refuses any query that is not a single SELECT.

Do we have to restructure our tables?

No. Your queries rename and shape the columns into Naarvin's template columns; the tables stay as they are.

Which databases are supported?

PostgreSQL, MySQL and MariaDB, and Microsoft SQL Server.

Where Naarvin helps

See it on your own books

A guided demo on Demo Group's books, then we connect one of your companies. In Arabic or English.