Skip to content

Instantly share code, notes, and snippets.

@jschoch
Last active December 19, 2015 15:28
Show Gist options
  • Select an option

  • Save jschoch/5976073 to your computer and use it in GitHub Desktop.

Select an option

Save jschoch/5976073 to your computer and use it in GitHub Desktop.
ran this in IEX
use Cnt
Amnesia.start
CntDBA.create_lots
Lots.last!
Enum.count iex(dsktest@ip-10-40-65-192)6> Cnt.Lots.last!
Cnt.Lots[id: 99999, oink: nil]
iex(dsktest@ip-10-40-65-192)7> Cnt.Lots.gt(999998)
** (MatchError) no match of right hand side value: {:aborted, {:function_clause, [{Amnesia.Table, :select, [Cnt.Lots, nil, [{Cnt.Lots[id: :"$1", oink: :"$2"], [{:>, :"$1", 999998}], [:"$_"]}]], [file: '/home/ec2-user/test/amnesia_test/deps/amnesia/lib/amnesia/table.ex', line: 537]}, {:mnesia_tm, :apply_fun, 3, [file: 'mnesia_tm.erl', line: 830]}, {:mnesia_tm, :execute_transaction, 5, [file: 'mnesia_tm.erl', line: 810]}, {Cnt.Lots, :gt, 1, [file: '/home/ec2-user/test/amnesia_test/lib/continuations.ex', line: 18]}, {:erl_eval, :do_apply, 6, [file: 'erl_eval.erl', line: 569]}, {:elixir, :eval_forms, 3, [file: 'src/elixir.erl', line: 152]}, {IEx.Server, :eval, 4, [file: '/home/ec2-user/elixir/lib/iex/lib/iex/server.ex', line: 112]}, {IEx.Server, :wait_input, 1, [file: '/home/ec2-user/elixir/lib/iex/lib/iex/server.ex', line: 52]}]}}
/home/ec2-user/test/amnesia_test/lib/continuations.ex:18: Cnt.Lots.gt/1
erl_eval.erl:569: :erl_eval.do_apply/6
src/elixir.erl:152: :elixir.eval_forms/3
/home/ec2-user/elixir/lib/iex/lib/iex/server.ex:112: IEx.Server.eval/4
/home/ec2-user/elixir/lib/iex/lib/iex/server.ex:52: IEx.Server.wait_input/1
/home/ec2-user/elixir/lib/iex/lib/iex/server.ex:63: IEx.Server.wait_input/1
/home/ec2-user/elixir/lib/iex/lib/iex/server.ex:31: IEx.Server.start/1
use Amnesia
require Exquisite
defdatabase Cnt do
@how_many 10000
deftable Lots, [:id, :oink],type: :ordered_set do
def run_next(list, nil) do
list
end
def run_next(list,selection) do
IO.puts "fetching more stuff, already found #{Enum.count list}"
run_next([selection.values|list],selection.next)
end
def gt(val) do
s = Exquisite.match Lots,
where: id > val
{:atomic,selection} = Amnesia.transaction do
Lots.select( @how_many, s)
end
IO.puts inspect selection
run_next([],selection)
end
def put_new do
c = Amnesia.Counter.get(:auto_increment_lots)
Amnesia.transaction! do
if (c.value == 0) do
IO.puts "Found zero counter"
count = Lots.last
if count != nil do
count = (count.id + 1)
c.increase count
end
end
r = Lots[id: c.value]
c.increase
r.write
r
end
end
end
end
defmodule CntDBA do
def install do
Amnesia.Schema.create
Amnesia.start
#Duse Cnt
Cnt.create(disk: [node])
Cnt.wait
#Amnesia.stop
end
def uninstall do
Amnesia.start
Cnt.destroy
Amnesia.stop
Amnesia.Schema.destroy
end
def create_lots do
lc x inlist Enum.to_list 1..100000 do
Cnt.Lots.put_new
end
end
end
iex(dsktest@ip-10-40-65-192)7> r Cnt
/home/ec2-user/test/amnesia_test/lib/continuations.ex:4: redefining module Cnt
/home/ec2-user/test/amnesia_test/lib/continuations.ex:6: redefining module Cnt.Lots
** (CompileError) /home/ec2-user/test/amnesia_test/lib/continuations.ex:6: cannot define module Cnt.Lots because it is currently being defined
/usr/local/lib/erlang/lib/parsetools-2.0.9/include/yeccpre.hrl:128: :elixir_parser.yecctoken_end_location/1
/usr/local/lib/erlang/lib/parsetools-2.0.9/include/yeccpre.hrl:113: :elixir_parser.yeccpars1/7
/usr/local/lib/erlang/lib/parsetools-2.0.9/include/yeccpre.hrl:56: :elixir_parser.yeccpars0/5
src/elixir_translator.erl:16: :elixir_translator.forms/4
src/elixir_translator.erl:28: :elixir_translator.forms!/4
src/elixir_compiler.erl:24: :elixir_compiler.string/2
/home/ec2-user/elixir/lib/elixir/lib/code.ex:266: Code.load_file/2
/home/ec2-user/elixir/lib/iex/lib/iex/helpers.ex:269: IEx.Helpers.do_r/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment