余劲峰 發表於 2025-3-22 00:00:00

Electron中如何使用SQLite数据库

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>介绍</li><li>准备工作</li><li>安装SQLite</li><li>连接SQLite数据库</li><li>创建表格</li><li>插入数据</li><li>查询数据</li><li>更新数据</li><li>删除数据</li><li>使用Sequelize</li></ul></div><p>Electron&nbsp;应用中常使用的数据库是&nbsp;SQLite、IndexedDB,IndexedDB&nbsp;是在前端网页中去操作。有的文章里说&nbsp;IndexedDB&nbsp;的性能会比&nbsp;SQLite&nbsp;更好,大家看实际场景去选择使用。大多数桌面应用或者 App 需要使用数据库的时候一般都是用&nbsp;SQLite。</p><p>npm 上有两个最常用的&nbsp;sqlite3&nbsp;库,一是&nbsp;better-sqlite3&nbsp;,一是&nbsp;node-sqlite&nbsp;,两种各有特点。前者是同步的 api ,执行速度快,后者是异步 api ,执行速度相对慢一点。值得注意的是,后者的编译支持 arm 机器,而且由于出的比较早,和其他库配合使用很方便。</p><p class="maodian"></p><h2>介绍</h2><p>Electron是一个流行的跨平台框架,用于构建桌面应用程序。它结合了Chromium和Node.js,使开发者能够使用Web技术(HTML、CSS和JavaScript)构建强大的本地应用程序。SQLite是一种轻量级的关系型数据库引擎,经常用于嵌入式系统和移动应用程序中。</p><p>本文将介绍如何在Electron应用程序中使用SQLite数据库。我们将探讨如何安装SQLite,执行基本的CRUD操作,以及使用一些流行的Node.js库来简化SQLite的使用。</p><p class="maodian"></p><h2>准备工作</h2><p>在开始之前,我们需要先安装一些必要的依赖库:</p><ul class=" list-paddingleft-2"><li>Git</li><li>Node.js</li><li>Electron</li></ul><p>安装完成后,我们可以继续进行后续的步骤。</p><p class="maodian"></p><h2>安装SQLite</h2><p>在Electron中使用SQLite之前,我们需要先安装SQLite。SQLite可以通过访问官方网站下载和安装。</p><p>安装完成后,我们需要在Electron项目的根目录中创建一个新的文件夹,用于存放SQLite数据库文件。</p><p class="maodian"></p><h2>连接SQLite数据库</h2><p>在Electron应用程序中,我们可以使用<code>sqlite3</code>模块来连接和操作SQLite数据库。首先,我们需要使用npm安装<code>sqlite3</code>模块:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">npm&nbsp;install&nbsp;sqlite3</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Bash</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>然后,在我们的Electron主进程文件(通常是<code>main.js</code>或<code>index.js</code>)中,我们可以按照以下步骤连接SQLite数据库:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">const&nbsp;sqlite3&nbsp;=&nbsp;require(&#39;sqlite3&#39;).verbose();const&nbsp;path&nbsp;=&nbsp;require(&#39;path&#39;);const&nbsp;dbPath&nbsp;=&nbsp;path.join(__dirname,&nbsp;&#39;./database/mydatabase.db&#39;);const&nbsp;db&nbsp;=&nbsp;new&nbsp;sqlite3.Database(dbPath);</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用了<code>sqlite3</code>模块来进行SQLite数据库的连接,并通过<code>path</code>模块构建了数据库的路径。然后,我们创建了一个<code>Database</code>对象,该对象表示数据库的连接。</p><p class="maodian"></p><h2>创建表格</h2><p>接下来,我们可以使用<code>db.run()</code>方法创建一个新的表格。下面是一个简单的示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">db.run(&#39;CREATE&nbsp;TABLE&nbsp;IF&nbsp;NOT&nbsp;EXISTS&nbsp;users&nbsp;(id&nbsp;INTEGER&nbsp;PRIMARY&nbsp;KEY&nbsp;AUTOINCREMENT,&nbsp;name&nbsp;TEXT,&nbsp;age&nbsp;INTEGER)&#39;);</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用<code>db.run()</code>方法创建了一个名为<code>users</code>的表格,并定义了三个列:<code>id</code>、<code>name</code>和<code>age</code>。</p><p class="maodian"></p><h2>插入数据</h2><p>要向表格中插入数据,我们可以使用<code>db.run()</code>方法和SQL&nbsp;INSERT语句。下面是一个示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">db.run(&#39;INSERT&nbsp;INTO&nbsp;users&nbsp;(name,&nbsp;age)&nbsp;VALUES&nbsp;(?,&nbsp;?)&#39;,&nbsp;[&#39;John&#39;,&nbsp;25]);</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用了SQL参数化查询来处理用户输入,以避免SQL注入攻击。</p><p class="maodian"></p><h2>查询数据</h2><p>要从表格中查询数据,我们可以使用<code>db.all()</code>方法和SQL&nbsp;SELECT语句。下面是一个示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">db.all(&#39;SELECT&nbsp;*&nbsp;FROM&nbsp;users&#39;,&nbsp;(err,&nbsp;rows)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;if&nbsp;(err)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(err);
&nbsp;&nbsp;&nbsp;&nbsp;return;
&nbsp;&nbsp;}

&nbsp;&nbsp;rows.forEach((row)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.log(row.id,&nbsp;row.name,&nbsp;row.age);
&nbsp;&nbsp;});});</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用了<code>db.all()</code>方法从<code>users</code>表格中选择所有的行,并使用回调函数处理查询结果。</p><p class="maodian"></p><h2>更新数据</h2><p>要更新表格中的数据,我们可以使用<code>db.run()</code>方法和SQL UPDATE语句。下面是一个示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">db.run(&#39;UPDATE&nbsp;users&nbsp;SET&nbsp;age&nbsp;=&nbsp;?&nbsp;WHERE&nbsp;name&nbsp;=&nbsp;?&#39;,&nbsp;);</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用了SQL参数化查询来更新名为<code>John</code>的用户的年龄为30。</p><p class="maodian"></p><h2>删除数据</h2><p>要删除表格中的数据,我们可以使用<code>db.run()</code>方法和SQL DELETE语句。下面是一个示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">db.run(&#39;DELETE&nbsp;FROM&nbsp;users&nbsp;WHERE&nbsp;age&nbsp;&gt;&nbsp;?&#39;,&nbsp;);</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们使用了SQL参数化查询来删除年龄大于30的用户。</p><p class="maodian"></p><h2>使用Sequelize</h2><p>在前面的示例中,我们直接使用了原始的SQLite API来执行操作。然而,如果我们想要使用更高级的功能,如ORM(对象关系映射),那么可以考虑使用Sequelize。Sequelize是一个流行的Node.js库,提供了一种更简单、更强大的方式来操作SQLite数据库。</p><p>首先,我们需要使用npm安装<code>sequelize</code>模块和<code>sqlite3</code>模块:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">npm&nbsp;install&nbsp;sequelize&nbsp;sqlite3</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Bash</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>然后,在我们的Electron主进程文件中,我们可以按照以下步骤来设置Sequelize:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">const&nbsp;Sequelize&nbsp;=&nbsp;require(&#39;sequelize&#39;);const&nbsp;path&nbsp;=&nbsp;require(&#39;path&#39;);const&nbsp;dbPath&nbsp;=&nbsp;path.join(__dirname,&nbsp;&#39;./database/mydatabase.db&#39;);const&nbsp;sequelize&nbsp;=&nbsp;new&nbsp;Sequelize({
&nbsp;&nbsp;dialect:&nbsp;&#39;sqlite&#39;,
&nbsp;&nbsp;storage:&nbsp;dbPath,});//&nbsp;定义模型const&nbsp;User&nbsp;=&nbsp;sequelize.define(&#39;User&#39;,&nbsp;{
&nbsp;&nbsp;name:&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;Sequelize.STRING,
&nbsp;&nbsp;&nbsp;&nbsp;allowNull:&nbsp;false,
&nbsp;&nbsp;},
&nbsp;&nbsp;age:&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;Sequelize.INTEGER,
&nbsp;&nbsp;&nbsp;&nbsp;allowNull:&nbsp;false,
&nbsp;&nbsp;},});//&nbsp;同步模型到数据库sequelize.sync()
&nbsp;&nbsp;.then(()&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#39;Database&nbsp;and&nbsp;tables&nbsp;created!&#39;);
&nbsp;&nbsp;})
&nbsp;&nbsp;.catch((err)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(&#39;Unable&nbsp;to&nbsp;connect&nbsp;to&nbsp;the&nbsp;database:&#39;,&nbsp;err);
&nbsp;&nbsp;});</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这个示例中,我们首先引入了<code>sequelize</code>和<code>sqlite3</code>模块。然后,我们使用<code>path</code>模块构建了数据库的路径,并使用<code>new Sequelize()</code>方法创建了一个Sequelize实例。</p><p>接下来,我们定义了一个名为<code>User</code>的模型,并定义了两个属性:<code>name</code>和<code>age</code>。最后,我们使用<code>sequelize.sync()</code>方法将模型同步到数据库。</p><p>使用Sequelize,我们可以更方便地进行CRUD操作。以下是一些示例:</p><div style="box-sizing: border-box; position: relative; color: rgb(33, 33, 33);"><pre style="box-sizing: border-box; overflow: auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: 20px;">//&nbsp;插入数据User.create({&nbsp;name:&nbsp;&#39;John&#39;,&nbsp;age:&nbsp;25&nbsp;})
&nbsp;&nbsp;.then((user)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.log(user.toJSON());
&nbsp;&nbsp;})
&nbsp;&nbsp;.catch((err)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(err);
&nbsp;&nbsp;});//&nbsp;查询数据User.findAll()
&nbsp;&nbsp;.then((users)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;users.forEach((user)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(user.toJSON());
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;})
&nbsp;&nbsp;.catch((err)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(err);
&nbsp;&nbsp;});//&nbsp;更新数据User.update({&nbsp;age:&nbsp;30&nbsp;},&nbsp;{&nbsp;where:&nbsp;{&nbsp;name:&nbsp;&#39;John&#39;&nbsp;}&nbsp;})
&nbsp;&nbsp;.then((result)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.log(result);
&nbsp;&nbsp;})
&nbsp;&nbsp;.catch((err)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(err);
&nbsp;&nbsp;});//&nbsp;删除数据User.destroy({&nbsp;where:&nbsp;{&nbsp;age:&nbsp;{&nbsp;:&nbsp;30&nbsp;}&nbsp;}&nbsp;})
&nbsp;&nbsp;.then((result)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.log(result);
&nbsp;&nbsp;})
&nbsp;&nbsp;.catch((err)&nbsp;=&gt;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;console.error(err);
&nbsp;&nbsp;});</pre><div style="box-sizing: border-box; position: absolute; top: 0.3em; right: 0.2em; transition: opacity 0.3s ease-in-out 0s; opacity: 0;"><div><span style="box-sizing: border-box; color: rgb(187, 187, 187); font-size: 0.8em; padding: 0px 0.5em; background: rgba(224, 224, 224, 0.2); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">JavaScript</span></div><div><button style="margin: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 0.8em; font-family: inherit; color: rgb(187, 187, 187); overflow: visible; appearance: button; cursor: pointer; background: rgba(224, 224, 224, 0.2); border-width: 0px; border-style: initial; border-color: initial; padding: 0px 0.5em; user-select: none; box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 0px 0px; border-radius: 0.5em;">Copy</button></div></div></div><p>在这些示例中,我们通过调用模型的方法来执行CRUD操作。</p><p>以上就是在Electron中使用SQLite数据库的基本介绍。通过使用SQLite,我们可以在Electron应用程序中存储和检索数据,并使用Sequelize可以更方便地进行CRUD操作。</p><p><br/></p>
頁: [1]
查看完整版本: Electron中如何使用SQLite数据库