emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/triples 668363c6e7 03/10: Provide triples-upgrade-to-0.


From: ELPA Syncer
Subject: [elpa] externals/triples 668363c6e7 03/10: Provide triples-upgrade-to-0.3 for builtin sqlite users
Date: Sat, 10 Jun 2023 13:00:10 -0400 (EDT)

branch: externals/triples
commit 668363c6e7399430fbd4f6e4297c6e55903d583a
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Andrew Hyatt <ahyatt@gmail.com>

    Provide triples-upgrade-to-0.3 for builtin sqlite users
    
    This function will convert all string integers into actual integers in the
    subject and object columns in the database.  The predicate and properties 
cannot
    be integers, so do not need conversion.
---
 NEWS.org           |  2 +-
 triples-upgrade.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/NEWS.org b/NEWS.org
index b64b006f27..35bee9ae6e 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,7 +1,7 @@
 TITLE: Changelog for the triples module for GNU Emacs.
 
 * 0.3
-- All integers are stored as integers, and not strings
+- All integers are stored as integers, and not strings.  Applications using 
this library in previous versions should have users run 
~triples-upgrade-to-0.3~.
 * 0.2.7
 - Add new function =triples-db-select-pred-op=, which allows querying among 
predicates for objects with a certain relationship to values, replaces 
=triples-db-select-predicate-object-fragment=.
 - Add ability to store cons types (basically lists) as values.
diff --git a/triples-upgrade.el b/triples-upgrade.el
new file mode 100644
index 0000000000..17d0f6d1c5
--- /dev/null
+++ b/triples-upgrade.el
@@ -0,0 +1,51 @@
+;;; triples-upgrade --- Functions to upgrade data from previous triple db 
version  -*- lexical-binding: t; -*-
+
+;; Copyright (c) 2023  Free Software Foundation, Inc.
+
+;; Author: Andrew Hyatt <ahyatt@gmail.com>
+;; Homepage: https://github.com/ahyatt/triples
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; Occasionally, changes in the triples library are not backwards-compatible,
+;; and require upgrading the database. This file contains functions to do those
+;; ugprades, along with instructions an how and when to use them.
+
+;;; Code:
+
+(require 'triples)
+
+(defun triples-upgrade-to-0.3 (db)
+  "Upgrade the DB to version 0.3.
+This will convert all stringified integers stored with sqlite to
+actual integers. On emacs version before 29, it will not do
+anything, since only the built-in sqlite data needs upgrading.
+Callers should force a backup to happen before calling this,
+with `(triples-backup db file most-positive-fixnum)'."
+  (if (or (version< emacs-version "29")
+          (not (eq (type-of db) 'sqlite)))
+      (message "Upgrade is only needed for the built-in sqlite databases used 
by emacs 29+")
+    (triples-with-transaction
+      db
+      (mapc (lambda (column)
+              (sqlite-execute
+               db
+               (format "UPDATE OR IGNORE triples SET %s = cast(REPLACE(%s, 
'\"', '') as integer) WHERE cast(REPLACE(%s, '\"', '') as integer) > 0"
+                       column column column)))
+            '("subject" "object"))
+      (message "Upgraded all stringified integers in triple database to actual 
integers"))))
+
+(provide 'triples-upgrade)
+;; triples-upgrade ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]