Comments (8)
This is not correct usage of KVS. The example of table creation you can see in n2o/samples.
Basically you need to plug KVS schema into sys.config
file.
$ cat sys.config
[
{kvs, [{dba,store_mnesia},
{schema, [kvs_feed ]} ]}
].
-module(kvs_feed).
metainfo() -> #schema{name=kvs,tables= core() }.
core()
-> [ #table{name=config,fields=record_info(fields,config)},
#table{name=log,container=true,fields=record_info(fields,log)},
#table{name=operation,container=log,fields=record_info(fields,operation)},
#table{name=id_seq,fields=record_info(fields,id_seq),keys=[thing]} ].
Just follow the examples. Did you try to read the README.md ? ;-)
from kvs.
This is wrong.
-record(text, {id=[], title=[], body=[]}).
Please read this fucking manual :-) You need to include ?ITERATOR field package in order this machinery to work.
from kvs.
When record has no ITER section it means you can't use kvs:add
, but only kvs:put
.
from kvs.
The story is that KVS after 3.3 KVS tables support versioning. It means you can tune KVS to rip the table when number of objects exceed some limit (in this example is 5):
> kvs:id_seq(user).
30
> kvs:config(user).
[{interval,31,infinity,user6,user},
{interval,25,30,user5,user},
{interval,19,24,user4,user},
{interval,13,18,user3,user},
{interval,7,12,user2,user}]
So when you read from mnesia
you see only 5 entries as they are stored in dedicated table.
> mnesia:transaction(fun() -> qlc:eval(mnesia:table(user4)) end).
{atomic,[{user4,19,[],feed,user,18,20,[],true,
[],[],[],[],[],[],
[],[],[],[],[],[],
[],[],[],[]},
{user4,20,[],feed,user,19,21,[],true,[],
[],[],[],[],[],[],
[],[],[],[],[],[],
[],[],[]},
{user4,21,[],feed,user,20,22,[],true,[],
[],[],[],[],[],[],
[],[],[],[],[],[],
[],[],...},
{user4,22,[],feed,user,21,23,[],true,[],
[],[],[],[],[],[],
[],[],[],[],[],[],
[],...},
{user4,23,[],feed,user,22,24,[],true,[],
[],[],[],[],[],[],
[],[],[],[],[],[],...},
{user4,24,[],feed,user,23,25,[],true,[],
[],[],[],[],[],[],
[],[],[],[],[],...}]}
But when you perform KVS traversal it uses config table and switch tables during traversal.
> length(kvs:entries(kvs:get(feed,user),user,infinity)).
30
This approach is not new, something similar happens in SQL and BitTables. But the reason I'm describing this here is directly connected with your questions. From 3.3 index fields (which is second field in record after atomic record name) should be.
> [ kvs:add(#user{id=kvs:next_id("user",1)}) || _ <- lists:seq(1,30) ], ok.
ok
That means when you populating data, you can put in id
field only integer. Because the table will selected on particular interval intersection (taken from list of intervals: kvs:config/1).
Hope this helps. It is clearly that you put <<"Test title">> as index for kvs:rname/1
[{erlang,atom_to_list,[<<"Test title">>],undefined}, {kvs,rname,1,383}
Could you please give me the KVS schema definition (not mnesia one) of your table?
from kvs.
Hi @5HT,
Thank you for your help!
This is all the code I wrote to create the table & schema:
-module(database_logic).
-include_lib("stdlib/include/qlc.hrl").
-export([init/0, insert/0]).
-record(text, {id=[], title=[], body=[]}).
init () ->
mnesia:create_table(text, [{attributes, record_info(fields, text)},
{type, bag},
{disc_copies, [node()]}]).
Hope this helps.
from kvs.
Ah yes, I've edited that file before! (I've been somewhat irritated by the example users.hrl file that you find in the review project)
Let me try again, and come back with the results.
from kvs.
I have succeeded in creating the table according to kvs's way, however, I'm still receiving an error in the console, when trying to insert data:
n2o_nitrogen:Pickle: {pickle,<<"submit">>,
<<"g2gCaAVkAAJldmQABXNtb2tlZAAGc3VibWl0bQAAAAZzdWJtaXRkAAVldmVudGgDYgAABepiAAZSgWIADjSt">>,
[{{"submit",<<"detail">>},[]},
{title,"weafwef"},
{body,"awefawef"}]}
n2o_nitrogen:Catch: error:badarg
[{erlang,atom_to_list,[<<"weafwef">>],undefined},
{kvs,rname,1,383},
{kvs,range,2,334},
{kvs,get,3,261},
{kvs,ensure_link,2,103},
My table schema has been -record(text, {id=[], title=[], body=[]}).
6> kvs:id_seq(text).
47
7> kvs:config(text).
[]
8> mnesia:transaction(fun() -> qlc:eval(mnesia:table(text)) end).
{atomic,[]}
9> length(kvs:entries(kvs:get(feed,text),text,infinity)).
0
10> [ kvs:add(#text{id=kvs:next_id("text",1)}) || _ <- lists:seq(1,30) ], ok.
* 1: record text undefined
getting undefined for user as well, a table which comes installed with kvs
11> [ kvs:add(#user{id=kvs:next_id("user",1)}) || _ <- lists:seq(1,30) ], ok.
* 1: record user undefined
Does this help?
from kvs.
I'm not having such a hard time reading the manual, and I've restarted the whole process with the ?ITERATOR field (note, in subscription.hrl there is no ?ITERATOR field as well for some reason).
And yes! It works!
Hope this may be beneficial to other newcomers. Thanks again, @5HT.
from kvs.
Related Issues (13)
- Add Kai and Riak storage modules to this repo HOT 1
- API breakdown: replace STRING to ATOM in id_seq HOT 1
- Move id_seq to separate schema HOT 4
- add support for configuring availability of entities HOT 1
- undefined function mongo:command/2 HOT 8
- grand code cleanups HOT 1
- feed/2 API
- kvs_stream:remove HOT 1
- bring store_riak back to life HOT 3
- convert remaining modules that involve feeds into containers/iterators HOT 1
- [KAI] user table has broken iterators support
- Use some semantic versioning HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kvs.