Giter VIP home page Giter VIP logo

documentstore's Introduction

DocumentStore

A document database with the typesafety and ease of use you want and the querying and indexing that you need.

  • Store data without defining schemas, tables or object models
  • The typesafety you're used to with Swift (No vars, forced unwrapping, casting or NSObjects)
  • Indexing makes efficient sorting and filtering possible
  • Non-blocking operations that run on a background thread by default
  • 100% client side, free to use open source database under MIT license

How does it work?

Define a document

struct TodoItem: Document, Codable {
  static let documentDescriptor = DocumentDescriptor<TodoItem>(name: "TodoItem",
                                                               identifier: Identifier(keyPath: \.id),
                                                               indices: [
                                                                 Index(name: "completed", keyPath: \.completed)
                                                               ])

  let id: Int
  let text: String
  let completed: Bool
}

Create a database

let documentStore = try DocumentStore(identifier: "TodoStore",
                                      documentDescriptors: [TodoItem.documentDescriptor])

Insert a document

let todoItem = TodoItem(id: 1, text: "Give DocumentStore a try", completed: false)

documentStore.write(handler: { result in
  if case let .failure(error) = result {
    fatalError(error)
  }
}, actions: { transaction in
  try transaction.insert(document: todoItem)
  return .saveChanges
})

Query for documents

let uncompletedQuery = Query<TodoItem>()
  .sorted(by: \.id, order: .ascending)
  .filtered { _ in !\.completed }

documentStore.read(handler: { result in
  switch result {
  case let .success(todoItems):
    debugPrint(todoItems)
  case let .failure(error):
    fatalError(error)
  }
}, actions: { transaction in
  try transaction.fetch(matching: uncompletedQuery)
})

When to use?

DocumentStore is a good fit when you want to:

  • persist items to disk
  • be able to sort and filter them
  • ease of use

Installation

TODO: Explain ways to use this in your project.

Limits

DocumentStore has no hard limits and is optimized for a few thousands of objects that are small to medium sized (up to ±1MB). Very big objects or a big number of documents may start to slow things down.

License

DocumentStore is created by Mathijs Kadijk and released under a MIT License.

documentstore's People

Contributors

mac-cain13 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.