【问题标题】:Local NoSQL database for desktop application用于桌面应用程序的本地 NoSQL 数据库
【发布时间】:2016-01-02 04:31:15
【问题描述】:

是否有类似 Sqlite 的桌面应用程序的 NoSQL 数据库解决方案,其中数据库是用户机器上的文件?该数据库将由桌面上使用的 nodejs 应用程序调用。

【问题讨论】:

    标签: node.js database nosql


    【解决方案1】:

    我使用 mongodb 本地实例。它非常容易设置。这是设置MongoDB的简单指南

    【讨论】:

    • 在此处添加更多信息。链接可能变得不可用。例如,一些例子。
    【解决方案2】:

    你也可以试试 couchdb。有一个例子伴随着电子

    http://blog.couchbase.com/build-a-desktop-app-with-github-electron-and-couchbase

    【讨论】:

      【解决方案3】:

      我知道这是一个老问题,但对您来说,一个较新的选项是 AceBase,它是一个快速、低内存、事务性、启用索引和查询的 NoSQL 数据库引擎和用于 node.js 和浏览器的服务器。绝对是 SQLite 的一个很好的 NoSQL 替代品,而且非常易于使用:

      const { AceBase } = require('acebase');
      const db = new AceBase('mydb');
      
      // Add question to database:
      const questionRef = await db.ref('stackoverflow/questions').push({ 
         title: 'Local NoSQL database for desktop application',
         askedBy: 'tt9',
         date: new Date(),
         question: 'Is there a NoSQL database solution for desktop applications similar to Sqlite where the database is a file on the user\'s machine? ..'
      });
      
      // questionRef is now a reference to the saved database path,
      // eg: "stackoverflow/questions/ky9v13mr00001s7b829tmwk1"
      
      // Add my answer to it:
      const answerRef = await questionRef.child('answers').push({
         text: 'Use AceBase!'
      });
      
      // answerRef is now reference to the saved answer in the database, 
      // eg: "stackoverflow/questions/ky9v13mr00001s7b829tmwk1/answers/ky9v5atd0000eo7btxid7uic"
      
      // Load the question (and all answers) from the database:
      const questionSnapshot = await questionRef.get();
      
      // A snapshot contains the value and relevant metadata, such as the used reference:
      console.log(`Got question from path "${questionSnapshot.ref.path}":`, questionSnapshot.val());
      
      // We can also monitor data changes in realtime
      // To monitor new answers being added to the question:
      questionRef.child('answers').on('child_added').subscribe(newAnswerSnapshot => {
         console.log(`A new answer was added:`, newAnswerSnapshot.val());
      });
      
      // Monitor any answer's number of upvotes:
      answerRef.child('upvotes').on('value').subscribe(snapshot => {
         const prevValue = snapshot.previous();
         const newValue = snapshot.val();
         console.log(`The number of upvotes changed from ${prevValue} to ${newValue}`);
      });
      
      // Updating my answer text:
      await answerRef.update({ text: 'I recommend AceBase!' });
      
      // Or, using .set on the text itself:
      await answerRef.child('text').set('I can really recommend AceBase');
      
      // Adding an upvote to my answer using a transaction:
      await answerRef.child('upvotes').transaction(snapshot => {
         let upvotes = snapshot.val();
         return upvotes + 1; // Return new value to store
      });
      
      // Query all given answers sorted by upvotes:
      let querySnapshots = await questionRef.child('answers')
         .query()
         .sort('upvotes', false) // descending order, most upvotes first
         .get();
      
      // Limit the query results to the top 10 with "AceBase" in their answers:
      querySnapshots = await questionRef.child('answers')
         .query()
         .filter('text', 'like', '*AceBase*')
         .take(10)
         .sort('upvotes', false) // descending order, most upvotes first
         .get();
      
      // We can also load the question in memory and make it "live":
      // The in-memory value will automatically be updated if the database value changes, and
      // all changes to the in-memory object will automatically update the database:
      
      const questionProxy = await questionRef.proxy();
      const liveQuestion = questionProxy.value;
      
      // Changing a property updates the database automatically:
      liveQuestion.tags = ['node.js','database','nosql'];
      
      // ... db value of tags is updated in the background ...
      
      // And changes to the database will update the liveQuestion object:
      let now = new Date();
      await questionRef.update({ edited: now });
      
      // In the next tick, the live proxy value will have updated:
      process.nextTick(() => {
         liveQuestion.edited === now; // true
      });
      

      我希望这对阅读本文的人有所帮助,AceBase 是一个相当新的孩子,正在开始掀起波澜!

      请注意,AceBase 也可以在浏览器中运行,并且可以作为具有完整身份验证和授权选项的远程数据库服务器。它可以与服务器和其他客户端实时同步,并在离线后重新连接。

      有关更多信息和文档,请查看AceBase at GitHub

      如果您想快速尝试以上示例,可以将代码复制/粘贴到 RunKit 的编辑器中:https://npm.runkit.com/acebase

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-21
        • 2011-08-09
        相关资源
        最近更新 更多