Giter Site home page Giter Site logo

Comments (6)

huahaiy avatar huahaiy commented on August 26, 2024 1

As per discussions on slack, requiring people to have a binding to use Datalevin functions seems a bit excessive, so we will keep the set-config function proposal, and hope people who have similar issues will land it here.

from datalevin.

huahaiy avatar huahaiy commented on August 26, 2024 1

Using print for regex is when importing/exporting data as text, so it is possible to only add the print-method when exporting.

from datalevin.

huahaiy avatar huahaiy commented on August 26, 2024 1

Just limit the change of print-method to dumping the DB.

from datalevin.

huahaiy avatar huahaiy commented on August 26, 2024

Because some data contains regex, in order to store and retrieve such data, print-method for regex was added, e.g. they are often used in transaction functions.

We can make this print-method optional for regex in order to support your use case. I can add a function set-confg to allow setting some global configurations. In this case, (set-config :store-regex? false) can be called to disable adding print-method for regex.

from datalevin.

jeroenvandijk avatar jeroenvandijk commented on August 26, 2024

I understand it is part of the serialization format. I would argue though that including the Datalevin namespace in your Clojure project should not break something that can be considered standard Clojure code. Especially for new users it would not be obvious to use your proposed setting. Also, what do you do when you need both. Maybe there is an alternative solution (idea below)?

Note: I haven't touched Datalevin much so I'm not sure about the impact of any change to this project.

;; in datalevin.bits

;; Don;t interfere with Clojure by default
(def :^dynamic *datalevin* false)

;; For Datalevin types *datalevin* is true
(defmethod print-method Indexable
  [^Indexable i, ^Writer w]
  (.write w "#datalevin/Indexable ")
  ;; This is Datalevin territory
  (binding [*datalevin* true]
    (.write w (pr-str (pr-indexable i)))))

;; Store original print-method
(defonce stdlib-print-method-pattern (get-method print-method java.util.regex.Pattern))

;; Depending on the *datalevin* value we will adapt printing for regex (and maybe others
(defmethod print-method Pattern
  [^Pattern p, ^Writer w]
  (if *datalevin*
    (doto w
      (.write "#datalevin/regex ")
      (.write "\"")
      (.write ^String (s/escape (.toString p) {\\ "\\\\"}))
      (.write "\""))
    ;; => Default Clojure's print behaviour here
    (stdlib-print-method-pattern p w)))

from datalevin.

den1k avatar den1k commented on August 26, 2024

Because some data contains regex, in order to store and retrieve such data, print-method for regex was added, e.g. they are often used in transaction functions.

is this because pr-str is used to write this data? Would it help to use custom functions similar to nippy's serialize?

from datalevin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.