erlang学习: Mnesia Erlang数据库

创建Mnesia数据库

erlang 复制代码
 mnesia:create_schema([node()]).

在shell里输入该行代码即可创建一个mnesia数据库于当前文件夹下

编译器文件路径下同样也有

数据库表定义创建

之后是数据库表定义,打开数据库创建完成后,启动数据库,添加一些表定义,添加完毕后关闭数据库

erlang 复制代码
-record(shop, {item, quantity, cost}).
-record(cost, {name, price}).
%% API
-export([do_this_once/0]).

do_this_once() ->
  mnesia:create_schema([node()]),
  mnesia:start(),
  mnesia:create_table(shop, [{attributes, record_info(fields, shop)}]),
  mnesia:create_table(cost, [{attributes, record_info(fields, cost)}]),
  mnesia:create_table(design, [{attributes, record_info(fields, design)}]),
  mnesia:stop().

按照书上的写编译会报错,少了一个record

在record中加一行回去

erlang 复制代码
-record(shop, {item, quantity, cost}).
-record(cost, {name, price}).
-record(design, {info, plan}).

这样就没问题了

相关推荐
minglie11 小时前
espidf的esp32版的webClient
学习
学运维的Kysan1 小时前
暑假运维学习打卡第二十五天8.16
学习
键盘飞行员2 小时前
Flutter App 全套实战学习计划:从零搭建到 APK 部署
学习·flutter
SomeOtherTime2 小时前
Postgresql触发器实现对表的日志审计
数据库·postgresql
这个DBA有点耶2 小时前
Oracle 迁移金仓兼容性评估指南:5 大维度深度拆解
数据库·oracle·架构
李可以量化3 小时前
Redis 从了解到精通(二)下:发布订阅进阶命令、量化场景落地与避坑指南
数据库·redis·python·qmt·ptrade
会编程的吕洞宾3 小时前
DeepAgents In Action学习(Second)
android·java·学习
添砖java‘’4 小时前
Redis中常用数据结构
数据库·redis·缓存
用户3169353811834 小时前
MyBatis Mapper XML 文件解读
数据库
我爱cope4 小时前
【计算机网络 | 数据链路层7:VLAN:一台交换机如何划分多个逻辑局域网?】
网络·学习·计算机网络