• mnesia


    1、模式创建

    mnesia:create_schema([node()|nodes()]).集群的节点之间创建模式

    2、启动和停止

    application:start(mnesia).

    application:stop(mnesia).

    3、创建表

    rd(usr,{msisdn,id,status,plan,services}).                                                                        usr
    (om@publicGroup1)18> Fields = record_info(fields,usr).
    [msisdn,id,status,plan,services]
    (om@publicGroup1)19> mnesia:create_table(usr,[{disc_copies,[node()]},{ram_copies,nodes()},{type,set},{attributes,Fields},{index,[id]}]).
    {atomic,ok}

    4、事务

    transaction(F).

    mnesia:transaction(fun() -> mnesia:index_read(usr, 700000002,id) end).

    mnesia:transaction(fun() -> mnesia:write(usr, Usr#usr{services=[ok]}).

    5、遍历

    (foo@publicGroup1)41> Fun = fun(#muppet{name="Francesco",salary = Salary},_) ->  
    (foo@publicGroup1)41> Salary;                                                    
    (foo@publicGroup1)41> (_,_) -> ok                                                
    (foo@publicGroup1)41> end.
    #Fun<erl_eval.12.111823515>
    (foo@publicGroup1)42> mnesia:transaction(fun() -> mnesia:foldl(Fun,ok,muppet) end).
    {atomic,0}

    6、脏操作

    mnesia:dirty_index_read(usr,700000002,id).

    mnesia:dirty_read({usr,PhoneNo}).

  • 相关阅读:
    不依赖OFFICE组件实现带图片的EXCEL导出
    关于安装SQL的错误
    Web开发学习点滴(持续更新)
    窗体间传值汇总
    沈阳.NET俱乐部MSN群开张了。。。
    VoIP协议标准浅析
    名词解释
    创建和运行一个解决方案
    400电话为什么叫免费电话?
    XPO基础简化的属性语法:
  • 原文地址:https://www.cnblogs.com/yanwei-wang/p/4649121.html
Copyright © 2020-2023  润新知