erlang mnesia数据库设置主键自增
Mnesia是erlang/otp自带的分布式数据库管理系统。mnesia配合erlang的实现近乎理想,但在实际使用当中差强人意,总会有一些不足。mnesia数据表没有主键自增的功能,但在mnesia函数中有一个自增函数可以用来生成自增的id,在后面的内容将讲述如何实现主键自增
Mnesia是erlang/otp自带的分布式数据库管理系统。mnesia配合erlang的实现近乎理想,但在实际使用当中差强人意,总会有一些不足。mnesia数据表没有主键自增的功能,但在mnesia函数中有一个自增函数可以用来生成自增的id,在后面的内容将讲述如何实现主键自增的功能。
参照SQLite的做法,就是在数据库中单独建立一个的sqlite_sequence表来做其他表的自增索引表。同样,我们也创建这样一个表erlang_sequence,用来索引其他表的自增id,看似麻烦,效果还是很理想。
-module(m). -export([init/0, reg/2]). -record(user, {id, name, age}). -record(erlang_sequence, {name, seq}).%自增索引表,维护其他表的自增id init() -> mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(erlang_sequence, [{attributes, record_info(fields, erlang_sequence)} , {type,set}, {disc_copies, [node()]} ]), mnesia:create_table(user, [{attributes, record_info(fields, user)} , {type,set}, {disc_copies, [node()]} ]), ok. reg(Name, Age) -> F = fun() -> UserId = mnesia:dirty_update_counter(erlang_sequence, user, 1), User = #user{id = UserId, name = Name, age = Age }, mnesia:write(User) end, mnesia:transaction(F), ok.
运行代码:
D:\>erl -mnesia dir '"mnesia"' Eshell V5.10.2 (abort with ^G) 1> c(m). {ok,m} 2> m:init(). ok 3> m:reg("xiaomin",18). ok 4> m:reg("xiaohong",17). ok 5> tv:start().
Mnesia数据库视图:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

1. First enter Weibo, then click on me in the lower right corner and select [Customer Service]. 2. Then enter [Watermark] in the search box and select [Set Weibo Image Watermark]. 3. Then click [Link] in the interface. 4. Then click [Image Watermark Settings] in the newly opened window. 5. Finally, check [Picture Center] and click [Save].

1. Open the Weibo client, click the three little dots on the editing page, and then click Scheduled Post. 2. After clicking on scheduled posting, there will be a time option on the right side of the publishing time. Set the time, edit the article, and click on the yellow words in the lower right corner to schedule posting. 3. The mobile version of Weibo does not currently support scheduled publishing. This function can only be used on the PC client!

When buying tickets on Damai.com, in order to ensure that the ticket purchase time can be accurately grasped, users can set a floating clock to grab tickets. The detailed setting method is below, let us learn together. How to bind the floating clock to Damai 1. Click to open the floating clock app on your phone to enter the interface, and click on the location where the flash sale check is set, as shown in the figure below: 2. After coming to the page of adding new records, click on Damai.com Copy the ticket purchase link page copied in. 3. Next, set the flash sale time and notification time below, turn on the switch button behind [Save to Calendar], and click [Save] below. 4. Click to turn on [Countdown], as shown in the figure below: 5. When the reminder time comes, click the [Start Picture-in-Picture] button below. 6. When the ticket purchase time comes

Douyin is one of the most popular short video platforms today. While enjoying the fun of short videos, users also hope to have better control over their time. Recently, some users reported that Douyin would automatically close during playback, which troubled them very much. 1. How to set the Douyin playback to automatically turn off? 1. Check the Douyin version. Please make sure that the Douyin version you are using is the latest. Douyin will be updated regularly to fix known issues. If your version of TikTok is too old, it may automatically close. You can check and update TikTok in the App Store. 2. Check the mobile phone system version. The automatic shutdown of Douyin playback may also be related to the mobile phone system version. Please make sure your mobile phone system version is the latest. If the mobile phone system version is too old, it may cause Douyin to run unstable. you can

The 3D mode of Google Maps is favored by users because it can present map information in a more three-dimensional way, allowing users to clearly view their location. Therefore, the editor of this article has prepared a method to enable the 3D map mode of the mobile version of Google Maps. Let’s learn together. . How to turn on the 3D map mode of Google Maps mobile version 1. First, enter the location you want to view at any time in the input box above. 2. After finding the location, click the small icon of the location shown in the picture below. 3. Then click [3D] in the function menu. Option 4. After selecting the 3D function to turn on, click on the location you want to view. You can see a small window in the lower left corner. Click on the window to enlarge. 5. Finally, we can see the 3D real-time street view.

1. Open the Weibo group chat and select Settings (as shown in the picture). 2. Select [Chat Bubble] (as shown in the picture). 3. After reaching the corresponding level, you can receive the bubbles and set them up (as shown in the picture).

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())
