Last active
December 19, 2015 15:19
-
-
Save jschoch/5975043 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Amnesia | |
require Exquisite | |
defmodule DBA do | |
def install do | |
Amnesia.Schema.create | |
Amnesia.start | |
use IndexTest | |
IndexTest.create(disk: [node]) | |
IndexTest.wait | |
Amnesia.stop | |
end | |
def uninstall do | |
Amnesia.start | |
IndexTest.destroy | |
Amnesia.stop | |
Amnesia.Schema.destroy | |
end | |
end | |
defdatabase IndexTest do | |
deftable Urls, [:pre,:post,:raw], type: :ordered_set do | |
def put(raw) do | |
[pre,post] = String.split(raw,"%40") | |
Amnesia.transaction do | |
Urls[pre: pre,post: post, raw: raw].write | |
end | |
end | |
end | |
deftable Domains, [:id,:root_id, :name,:created_at,:updated_at], type: :ordered_set do | |
def put_new(id,root_id,name) do | |
Amnesia.transaction do | |
created_at = :calendar.now_to_datetime(:erlang.now) | |
updated_at = created_at | |
Domains[id: id, root_id: root_id, name: name,created_at: created_at,updated_at: updated_at].write | |
end | |
end | |
end | |
#@ds Exquisite.match Domains, where: :root_id = | |
#deftable Roots, [:id,:name], type: :ordered_set, index: [:name] do | |
deftable Roots, [:id,:name,:updated_at], type: :ordered_set do | |
def run_next(list, nil) do | |
list | |
end | |
def run_next(list,selection) do | |
run_next([selection.values|list],selection.next) | |
end | |
def domains(self) do | |
s = Exquisite.match Domains, | |
where: root_id == self.id | |
{:atomic,selection} = Amnesia.transaction do | |
Domains.select( s) | |
end | |
IO.puts inspect selection | |
run_next([],selection) | |
end | |
def new_domains(self,at) do | |
s = Exquisite.match Domains, | |
where: root_id == self.id and created_at > at | |
res = Amnesia.transaction do | |
Domains.select( s) | |
end | |
parse_select(res) | |
end | |
def noo(name) do | |
c = Amnesia.Counter.get(:index_test_roots) | |
Amnesia.transaction! do | |
if (c.value == 0) do | |
IO.puts "Found zero counter" | |
count = Roots.last | |
if count != nil do | |
count = (count.id + 1) | |
c.increase count | |
end | |
end | |
r = Roots[id: c.value,name: name] | |
c.increase | |
r.write | |
r | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment