Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java embedded nosql document store

License

NotificationsYou must be signed in to change notification settings

lykmapipo/nitrite-database

 
 

Repository files navigation

Donate using LiberapayBuild StatusCoverage StatusJavadocsGitterBackers on Open CollectiveBackers on Open Collective

Logo 200

NOsqlObject (NO2 a.k.a Nitrite) database is an open source nosql embeddeddocument store written in Java. It has MongoDB like API. It supports bothin-memory and single file based persistent store powered byMVStore engine of h2 database.

Nitrite is a server-less embedded database ideal for desktop, mobile or small web applications.

It features:

  • Embedded key-value/document and object store

  • In-memory or single data file

  • Very fast and lightweight MongoDB like API

  • Indexing

  • Full text search capability

  • Full Android compatibility

  • Observable store

  • Both way replication via Nitrite DataGate server

Kotlin Extension

Nitrite has a kotlin extension calledPotassium Nitrite for kotlin developers.Visithere for more details.

Data Explorer

To view the data of a nitrite database file, useNitrite Explorer. More detailscan be foundhere.

Data Replication

To replicate data over different devices automatically, useNitrite DataGate server. For more detailsvisithere.

Getting Started with Nitrite

How To Install

To use Nitrite in any Java application, just add the below dependency:

Maven

<dependency>    <groupId>org.dizitart</groupId>    <artifactId>nitrite</artifactId>    <version>{version}</version></dependency>

Gradle

compile'org.dizitart:nitrite:{version}'

Quick Examples

Initialize Database

//java initializationNitritedb =Nitrite.builder()        .compressed()        .filePath("/tmp/test.db")        .openOrCreate("user","password");//android initializationNitritedb =Nitrite.builder()        .compressed()        .filePath(getFilesDir().getPath() +"/test.db")        .openOrCreate("user","password");

Create a Collection

// Create a Nitrite CollectionNitriteCollectioncollection =db.getCollection("test");// Create an Object RepositoryObjectRepository<Employee>repository =db.getRepository(Employee.class);

Annotations for POJO

// provides index information for ObjectRepository@Indices({@Index(value ="joinDate",type =IndexType.NonUnique),@Index(value ="name",type =IndexType.Unique)})publicclassEmployeeimplementsSerializable {// provides id field to uniquely identify an object inside an ObjectRepository@IdprivatelongempId;privateDatejoinDate;privateStringname;privateStringaddress;// ... public getters and setters}

CRUD Operations

// create a document to populate dataDocumentdoc =createDocument("firstName","John")     .put("lastName","Doe")     .put("birthDay",newDate())     .put("data",newbyte[] {1,2,3})     .put("fruits",newArrayList<String>() {{add("apple");add("orange");add("banana"); }})     .put("note","a quick brown fox jump over the lazy dog");// insert the documentcollection.insert(doc);// update the documentcollection.update(eq("firstName","John"),createDocument("lastName","Wick"));// remove the documentcollection.remove(doc);
// insert an objectEmployeeemp =newEmployee();emp.setEmpId(124589);emp.setFirstName("John");emp.setLastName("Doe");repository.insert(emp);

Create Indices

// create document indexcollection.createIndex("firstName",indexOptions(IndexType.NonUnique));collection.createIndex("note",indexOptions(IndexType.Fulltext));// create object index. It can also be provided via annotationrepository.createIndex("firstName",indexOptions(IndexType.NonUnique));

Query a Collection

Cursorcursor =collection.find(// and clauseand(// firstName == Johneq("firstName","John"),// elements of data array is less than 4elemMatch("data",lt("$",4)),// elements of fruits list has one element matching orangeelemMatch("fruits",regex("$","orange")),// note field contains string 'quick' using full-text indextext("note","quick")                            )                        );for (Documentdocument :cursor) {// process the document}// create document by idDocumentdocument =collection.getById(nitriteId);// query an object repository and create the first resultEmployeeemp =repository.find(eq("firstName","John"))                         .firstOrDefault();

Automatic Replication

// connect to a DataGate server running at localhost 9090 portDataGateClientdataGateClient =newDataGateClient("http://localhost:9090")        .withAuth("userId","password");DataGateSyncTemplatesyncTemplate        =newDataGateSyncTemplate(dataGateClient,"remote-collection@userId");// create sync handleSyncHandlesyncHandle =Replicator.of(db)        .forLocal(collection)// a DataGate sync template implementation        .withSyncTemplate(syncTemplate)// replication attempt delay of 1 sec        .delay(timeSpan(1,TimeUnit.SECONDS))// both-way replication        .ofType(ReplicationType.BOTH_WAY)// sync event listener        .withListener(newSyncEventListener() {@OverridepublicvoidonSyncEvent(SyncEventDataeventInfo) {            }        })        .configure();// start sync in the background using handlesyncHandle.startSync();

Import/Export Data

// Export data to a fileExporterexporter =Exporter.of(db);exporter.exportTo(schemaFile);//Import data from the fileImporterimporter =Importer.of(db);importer.importFrom(schemaFile);

More details are available in the reference document.

Release Notes

Release notes are availablehere.

Documentation

ReferenceAPI

Document

JavaDoc

Build

To build and test Nitrite

$ git clone https://github.com/dizitart/nitrite-database.git$cd nitrite-database$ ./gradlew build

The test suite requires mongod to be running on localhost, listening on the default port. MongoDb is requiredto test replication using the DataGate server. Please run the below command to create the test user in mongo.

db.getSiblingDB('benchmark').createUser({user:'bench',pwd:'bench',roles:[{role:'readWrite',db:'benchmark'},{role:'dbAdmin',db:'benchmark'}]})

The test suite also requires android sdk 24.4.1 to be installed and ANDROID_HOME environment variable to be setupproperly to test the android example.

Support / Feedback

For issues with, questions about, or feedback talk to us atGitter.

Bugs / Feature Requests

Think you’ve found a bug? Want to see a new feature in the Nitrite? Please open an issuehere. Butbefore you file an issue please check if it is already existing or not.

Maintainers

  • Anindya Chatterjee

Contributors

This project exists thanks to all the people who contribute.Contribute.Contributors

Backers

Thank you to all our backers! 🙏Become a backer

Backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.Become a sponsor

SponsorSponsorSponsorSponsorSponsor

Packages

No packages published

Languages

  • Java71.1%
  • JavaScript20.5%
  • CSS3.5%
  • HTML2.6%
  • Kotlin2.2%
  • Shell0.1%

[8]ページ先頭

©2009-2025 Movatter.jp