~pepe/mansion

77f2573f48fc63f4e75cc39acd670554ed988e83 — Josef Pospíšil 1 year, 7 months ago b2f8463 + 59b9d6f
Merge branch 'master' of git.sr.ht:~pepe/mansion
3 files changed, 39 insertions(+), 6 deletions(-)

A LICENSE
M mansion/buffet/init.janet
M project.janet
A LICENSE => LICENSE +19 -0
@@ 0,0 1,19 @@
Copyright (c) 2021 Josef Pospíšil <josef.pospisil@laststar.eu>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.

M mansion/buffet/init.janet => mansion/buffet/init.janet +16 -2
@@ 77,7 77,20 @@
      (:destroy batch))
    id))

(defn- starts-with-index [indices]
  (fn [val] (some |(straing/has-prefix? $ val) indices)))

# @todo reindex
(defn- reindex [self]
  (def iter (:terator (self :db)))
  (def batch (t/batch/create))
  (:seek-to-first iter)
  (while (:valid? iter)
    (def k (:key iter))
    (when ((starts-with-index (self :to-index)) k) (:delete batch k))
    (:next iter))
  (:release (:write batch))
  (destroy iterator))

(defn- load [self id]
  (assert (string? id) (must-err "string" id))


@@ 121,7 134,7 @@
(defn- retrieve [self what &opt options]
  (default options @{})
  (when (options :id?) (put options :populate? true))
  (with [iter (t/iterator/create (self :db)) |(:destroy $)] #@fixme buffet prop
  (with [iter (:iterator (self :db)) |(:destroy $)] #@fixme buffet prop
    (def ids
      (cond
        (= what :all) (:_all self iter (options :limit))


@@ 152,7 165,8 @@
    :write write
    :save save
    :load load
    :retrieve retrieve})
    :retrieve retrieve
    :re-index re-index})

(defn create [name &opt buffet]
  (default buffet @{:to-index []})

M project.janet => project.janet +4 -4
@@ 1,7 1,10 @@
(declare-project
  :name "mansion"
  :author "Josef Pospíšil <josef.pospisil@laststar.eu>"
  :description "Place for tahani"
  :description "Place for Tahani"
  :deprecated true
  :repo "https://git.sr.ht/~pepe/mansion"
  :url "https://good-place.org/packages/mansion.html"
  :dependencies ["https://github.com/janet-lang/jhydro.git"
                 "https://github.com/janet-lang/spork.git"
                 "https://github.com/pepe/tahani"])


@@ 9,6 12,3 @@
(declare-source
  :name "mansion"
  :source @["mansion/"])

# run repl with tahani included
(phony "repl" ["build"] (os/execute ["janet" "-r" "-e" "(import mansion :as m)"] :p))