### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Configure Gradle Repository for Snapshot Builds
Source: https://nitrite.dizitart.com/java-sdk/getting-started/index
This Gradle snippet shows how to add the Sonatype snapshot repository to your `build.gradle` file, enabling access to development builds of Nitrite.
```gradle
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
```
--------------------------------
### Configure Maven Repository for Snapshot Builds
Source: https://nitrite.dizitart.com/java-sdk/getting-started/index
This XML configuration snippet shows how to add the Sonatype snapshot repository to your Maven `pom.xml` file, enabling access to development builds of Nitrite.
```xml
sonatype-snapshot
https://oss.sonatype.org/content/repositories/snapshots/
false
true
```
--------------------------------
### Add Gradle Dependency for Nitrite
Source: https://nitrite.dizitart.com/java-sdk/getting-started/index
This snippet demonstrates how to add the Nitrite BOM to your Gradle project for version management and then includes the core Nitrite artifact.
```gradle
dependencies {
implementation platform('org.dizitart:nitrite-bom:[latest version]')
implementation 'org.dizitart:nitrite'
}
```
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Add Maven Dependency for Nitrite
Source: https://nitrite.dizitart.com/java-sdk/getting-started/index
This snippet shows how to add the Nitrite Bill of Materials (BOM) to your Maven project for dependency management and then includes the core Nitrite artifact.
```xml
org.dizitart
nitrite-bom
[latest version]
import
pom
org.dizitart
nitrite
```
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Configure Gradle Repository for Snapshot Builds
Source: https://nitrite.dizitart.com/kotlin-sdk/getting-started/index
This Gradle snippet configures a project to use the Sonatype snapshot repository. This allows Gradle to download snapshot versions of libraries, which are useful for testing pre-release or development builds of dependencies like the Nitrite SDK.
```gradle
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
```
--------------------------------
### Get NitriteBuilder Instance
Source: https://nitrite.dizitart.com/java-sdk/database/index
Retrieves an instance of NitriteBuilder to configure and create a Nitrite database. This is the starting point for all database operations.
```java
NitriteBuilder builder = Nitrite.builder();
```
--------------------------------
### List Menu Activity Initialization and Adapter Setup (Java)
Source: https://nitrite.dizitart.com/examples/java/index
This Java code sets up the `ListMenuActivity` by initializing a ListView, creating a list of `TodoList` objects, and setting a `CustomAdapter` to populate the list. The `CustomAdapter` is responsible for inflating the `task_menu_item` layout and handling clicks to navigate to the `ToDoListActivity`. Dependencies include Android's `AppCompatActivity`, `ListView`, `ArrayList`, and custom `TodoList` and `CustomAdapter` classes.
```Java
public class ListMenuActivity extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_menu);
listView = (ListView) findViewById(R.id.listMenu);
ArrayList lists = new ArrayList<>();
lists.add(new TodoList("Home", "blue"));
lists.add(new TodoList("Work", "green"));
lists.add(new TodoList("School", "violet"));
CustomAdapter customAdapter = new CustomAdapter(lists);
listView.setAdapter(customAdapter);
}
public class CustomAdapter extends BaseAdapter {
ArrayList lists;
public CustomAdapter(ArrayList lists) {
this.lists = lists;
}
@Override
public int getCount() {
return lists.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.task_menu_item, null);
//region setting background color
RelativeLayout layout = view.findViewById(R.id.itemBackground);
final String color = lists.get(i).getColor();
if (color.matches("blue"))
layout.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.list_item_background_blue));
else if (color.matches("green"))
layout.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.list_item_background_green));
else
layout.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.list_item_background_violet));
//endregion
final TextView title = view.findViewById(R.id.listName);
title.setText(lists.get(i).getName());
ImageButton button = view.findViewById(R.id.selectList);
button.setOnClickListener(view1 -> listSelected(title.getText().toString(), color));
return view;
}
void listSelected(String listName, String listColor) {
Intent intent = new Intent(getApplicationContext(), ToDoListActivity.class);
intent.putExtra("listName", listName);
intent.putExtra("listColor", listColor);
startActivity(intent);
}
}
}
```
--------------------------------
### Untitled
No description
--------------------------------
### Add Nitrite Kotlin Dependency - Maven
Source: https://nitrite.dizitart.com/kotlin-sdk/getting-started/index
This snippet shows how to add the Nitrite Kotlin SDK dependency to a Maven project's pom.xml. It includes dependency management using the nitrite-bom for version control and specifies the potassium-nitrite artifact for Kotlin support.
```xml
org.dizitart
nitrite-bom
[latest version]
import
pom
org.dizitart
potassium-nitrite
```
--------------------------------
### Add Nitrite Kotlin Dependency - Gradle
Source: https://nitrite.dizitart.com/kotlin-sdk/getting-started/index
This snippet demonstrates how to add the Nitrite Kotlin SDK dependency to a Gradle project's build.gradle file. It utilizes the platform() function with the nitrite-bom for version management and declares the potassium-nitrite dependency for Kotlin.
```gradle
dependencies {
implementation platform('org.dizitart:nitrite-bom:[latest version]')
implementation 'org.dizitart:potassium-nitrite'
}
```
--------------------------------
### Untitled
No description
--------------------------------
### Add Nitrite Dependency to Flutter Project
Source: https://nitrite.dizitart.com/flutter-sdk/getting-started/index
This command adds the core Nitrite database package to your Flutter project's dependencies. Nitrite is a pure Dart database that can be used in any Dart-supported platform, including Flutter, Dart VM, and the browser.
```bash
dart pub add nitrite
```
--------------------------------
### Add Nitrite Hive Storage Adapter Dependency
Source: https://nitrite.dizitart.com/flutter-sdk/getting-started/index
This command adds the Hive storage adapter for Nitrite to your project. The Hive adapter allows Nitrite to leverage Hive for efficient data storage and retrieval, making it suitable for mobile, desktop, and web applications.
```bash
dart pub add nitrite_hive_adapter
```
--------------------------------
### Add Nitrite Code Generator Dependencies
Source: https://nitrite.dizitart.com/flutter-sdk/getting-started/index
These commands add the build runner and the Nitrite code generator as development dependencies. The code generator is crucial for optimizing Nitrite's performance and functionality within your project.
```bash
dart pub add --dev build_runner
dart pub add --dev nitrite_generator
```
--------------------------------
### Untitled
No description
--------------------------------
### Loading a Custom Plugin in Nitrite
Source: https://nitrite.dizitart.com/java-sdk/modules/module-system/index
Provides an example of how to load a custom Nitrite plugin. This typically involves creating a module that encapsulates the plugin and then loading the module.
```java
MyPlugin plugin = new MyPlugin();
MyModule module = new MyModule(plugin);
Nitrite db = Nitrite.builder()
.loadModule(module)
.openOrCreate("user", "password");
```
--------------------------------
### Implementing a NitriteStore Plugin
Source: https://nitrite.dizitart.com/java-sdk/modules/module-system/index
An example of implementing the NitriteStore interface, which serves as the base for storage plugins in Nitrite. This class would contain the logic for data storage and retrieval.
```java
public class MyStore implements NitriteStore {
// implement the methods
}
```
--------------------------------
### Example Custom Jackson Module
Source: https://nitrite.dizitart.com/java-sdk/modules/jackson/index
This Java code provides an example of a custom Jackson module ('MyCustomModule') that extends 'SimpleModule'. It demonstrates how to set up custom serializers and deserializers for specific types.
```java
public class MyCustomModule extends SimpleModule {
@Override
public void setupModule(SetupContext context) {
addSerializer(MyCustomType.class, new MyCustomTypeSerializer());
addDeserializer(MyCustomType.class, new MyCustomTypeDeserializer());
super.setupModule(context);
}
}
```
--------------------------------
### Initialize a Nitrite Plugin
Source: https://nitrite.dizitart.com/flutter-sdk/modules/module-system/index
Provides an example of initializing a Nitrite plugin by implementing the 'initialize' method from the NitritePlugin interface in Dart. This method is invoked when the plugin is loaded by its module.
```dart
class MyPlugin implements NitritePlugin {
@override
Future initialize(NitriteConfig nitriteConfig) async {
// do something
}
}
```
--------------------------------
### Create and Get NitriteCollection Instance
Source: https://nitrite.dizitart.com/flutter-sdk/collection/intro/index
Demonstrates how to initialize a Nitrite database and retrieve a collection instance. If the collection does not exist, it will be created automatically. This process is asynchronous.
```dart
var db = await nitriteBuilder()
.openOrCreate();
var collection = await db.getCollection("myCollection");
```
--------------------------------
### Equality Filter Example (Java)
Source: https://nitrite.dizitart.com/java-sdk/filter/index
Provides a code example in Java for using an equality filter to find documents where a field's value exactly matches a specified string. This is a fundamental comparison filter operation in NitriteDB.
```java
collection.find(where("name").eq("John"));
```
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Add Nitrite and Hive Dependencies
Source: https://nitrite.dizitart.com/flutter-sdk/modules/store-modules/hive/index
Installs the necessary Nitrite and Nitrite Hive adapter packages for your Dart project using the `dart pub add` command.
```bash
dart pub add nitrite
dart pub add nitrite_hive_adapter
```
--------------------------------
### Untitled
No description
--------------------------------
### Using and Opening MVStore Database
Source: https://nitrite.dizitart.com/java-sdk/modules/store-modules/mvstore/index
Demonstrates how to load and configure the MVStoreModule with a specified file path and compression, then open or create the Nitrite database.
```java
// configure the module
MVStoreModule storeModule = MVStoreModule.withConfig()
.filePath(filePath)
.compress(true)
.build();
Nitrite db = Nitrite.builder()
.loadModule(storeModule)
.openOrCreate();
```
--------------------------------
### Kotlin API for NitriteCollection
Source: https://nitrite.dizitart.com/kotlin-sdk/collection/index
Demonstrates the Kotlin API for interacting with a NitriteCollection. It shows how to get a collection, insert documents, and create an index using a higher-order function for simplified operations.
```kotlin
db.getCollection("myCollection") {
// do something with collection
insert(documentOf("firstName" to "John", "lastName" to "Doe"))
createIndex("firstName")
}
```
--------------------------------
### Initialize Nitrite Database with Singleton Pattern (Java)
Source: https://nitrite.dizitart.com/examples/java/index
This Java code demonstrates how to initialize a Nitrite database using a singleton pattern to ensure a single instance of the database connection. It includes methods for opening the database, handling its closing, and retrieving a repository for a specific entity type. Dependencies include Nitrite, MVStoreModule, SimpleDocumentMapper, and a custom TodoItem class with its Converter.
```java
public class NitriteManager {
private static NitriteManager _instance = new NitriteManager();
private static final String dbName = "task.db";
private static Nitrite db;
private NitriteManager() {}
public static NitriteManager getInstance() {
return _instance;
}
private void openDb(Context context) {
if (db != null) {
db.close();
}
MVStoreModule storeModule = MVStoreModule.withConfig()
.filePath(context.getDatabasePath(dbName))
.build();
SimpleDocumentMapper documentMapper = new SimpleDocumentMapper();
documentMapper.registerEntityConverter(new TodoItem.Converter());
db = Nitrite.builder()
.loadModule(storeModule)
.loadModule(() -> setOf(documentMapper))
.openOrCreate();
}
public ObjectRepository getTodoRepository(Context context, String label) {
if (db == null) {
openDb(context);
}
return db.getRepository(TodoItem.class, label);
}
}
```
--------------------------------
### Untitled
No description
--------------------------------
### Get FindPlan for a Cursor in NitriteDB
Source: https://nitrite.dizitart.com/flutter-sdk/repository/read/index
Shows how to retrieve the FindPlan of a cursor in NitriteDB. The FindPlan provides details about how the database will execute a find operation, useful for performance analysis. This example fetches a specific product.
```dart
Cursor cursor = productRepository.find(filter: where('productName').eq('Apple iPhone 6'));
var findPlan = await cursor.findPlan;
```
--------------------------------
### Start a Nitrite Database Transaction
Source: https://nitrite.dizitart.com/flutter-sdk/transaction/index
Provides an example of initiating a new transaction within an existing session. Transactions allow for atomic operations, ensuring that a series of database modifications are either all applied or none are. The `beginTransaction()` method returns a `Transaction` object.
```javascript
// start a transaction
var transaction = await session.beginTransaction();
```
--------------------------------
### Configure MVStore Module Builder
Source: https://nitrite.dizitart.com/java-sdk/modules/store-modules/mvstore/index
Illustrates the use of the MVStoreModule.withConfig() builder pattern to set specific configuration options like file path and compression before building the module.
```java
MVStoreModule storeModule = MVStoreModule.withConfig()
.filePath(filePath)
.compress(true)
.build();
```
--------------------------------
### Get Nitrite Database Transaction State
Source: https://nitrite.dizitart.com/flutter-sdk/transaction/index
Provides an example of retrieving the current state of a Nitrite database transaction using the `getState()` method. The method returns an enum value indicating whether the transaction is active, committed, closed, or in another specific state.
```javascript
// get transaction state
var state = transaction.getState();
```
--------------------------------
### Untitled
No description
--------------------------------
### Create and Apply NitriteDB Schema Migration
Source: https://nitrite.dizitart.com/flutter-sdk/migration/index
Demonstrates how to define a NitriteDB schema migration, including instructions for database and repository modifications, and then apply this migration to open or create a database. This involves setting up the migration with a version range and a set of instructions, then configuring the Nitrite builder.
```dart
// create a migration
var migration = Migration(1, 2, (instructionSet) {
instructionSet
.forDatabase()
.addUser('test-user', 'test-password');
instructionSet
.forRepository(key: 'demo1')
.renameRepository('new')
.changeDataType('empId', (value) => int.parse(value))
.changeIdField(Fields.withNames(['uuid']), Fields.withNames(['empId']))
.deleteField('uuid')
.renameField('lastName', 'familyName')
.addField('fullName', generator: (document) => '${document['firstName']} ${document['familyName']}')
.dropIndex(['firstName'])
.dropIndex(['literature.text'])
.changeDataType('literature.ratings', (value) => (value as double).round());
},
);
// apply the migration
var db = Nitrite.builder()
.loadModule(storeModule)
.schemaVersion(1)
.addMigration(migration)
.openOrCreate('test-user', 'test-password');
```
--------------------------------
### Initializing a NitritePlugin
Source: https://nitrite.dizitart.com/java-sdk/modules/module-system/index
Demonstrates the initialization process for a Nitrite plugin. The initialize() method is called by the module when the plugin is loaded, providing access to the Nitrite configuration.
```java
public class MyPlugin implements NitritePlugin {
@Override
public void initialize(NitriteConfig nitriteConfig) {
// initialize the plugin
}
}
```
--------------------------------
### Create Nitrite Database Builder
Source: https://nitrite.dizitart.com/flutter-sdk/database/index
Initializes the Nitrite database builder, which is the starting point for configuring and creating a Nitrite database instance. No specific dependencies are required for this basic builder creation.
```dart
var builder = Nitrite.builder();
```
--------------------------------
### Untitled
No description
--------------------------------
### Create MVStore Backed On-Disk Database
Source: https://nitrite.dizitart.com/java-sdk/database/index
Creates a Nitrite database persisted on disk using the MVStore storage engine. Requires the MVStoreModule and specifies the file path for the database.
```java
MVStoreModule storeModule = MVStoreModule.withConfig()
.filePath("/path/to/my.db")
.build();
Nitrite db = Nitrite.builder()
.loadModule(storeModule)
.openOrCreate();
```
--------------------------------
### Create and Apply NitriteDB Schema Migration
Source: https://nitrite.dizitart.com/java-sdk/migration/index
This snippet demonstrates how to define a schema migration in Java for NitriteDB. It includes creating a `Migration` object with source and target schema versions, defining migration instructions within the `migrate` method, and then applying this migration when opening or creating the database using `Nitrite.builder()`. The builder configuration includes loading a store module, setting the initial schema version, adding the migration, and then opening or creating the database with user credentials.
```java
import org.dizitart.no2.store.StoreModule;
import org.dizitart.no2.migration.Migration;
import org.dizitart.no2.migration.InstructionSet;
import org.dizitart.no2.util.TypeConverter;
import org.dizitart.no2.common.Fields;
import org.dizitart.no2.Nitrite;
// Assume OldClass and OldClassEntityDecorator are defined elsewhere
// Assume storeModule is a configured StoreModule instance
// Create a migration
Migration migration = new Migration(1, 2) {
@Override
public void migrate(InstructionSet instruction) {
instruction.forDatabase()
.addUser("test-user", "test-password");
instruction.forRepository(OldClass.class, "demo1")
.renameRepository("new", null)
.changeDataType("empId", (TypeConverter) Long::parseLong)
.changeIdField(Fields.withNames("uuid"), Fields.withNames("empId"))
.deleteField("uuid")
.renameField("lastName", "familyName")
.addField("fullName", document -> document.get("firstName", String.class) + " "
+ document.get("familyName", String.class)) // Assuming 'firstName' exists
.dropIndex("firstName")
.dropIndex("literature.text")
.changeDataType("literature.ratings", (TypeConverter) Math::round);
}
};
// Apply the migration
Nitrite db = Nitrite.builder()
.loadModule(storeModule)
.schemaVersion(1)
.addMigrations(migration)
.openOrCreate("test-user", "test-password");
```
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Start and Commit Transaction on NitriteCollection (Java)
Source: https://nitrite.dizitart.com/java-sdk/transaction/index
Demonstrates how to start a transaction, retrieve a NitriteCollection within that transaction, perform insert operations, and commit the transaction. It's recommended to use try-with-resource for transaction management.
```java
// start a transaction
Transaction transaction = session.beginTransaction();
// get a collection
NitriteCollection collection = transaction.getCollection("test");
// perform operations on the collection
collection.insert(doc1);
// commit the transaction
transaction.commit();
```
```java
try (Session session = db.createSession()) {
try (Transaction transaction = session.beginTransaction()) {
NitriteCollection collection = transaction.getCollection("test");
collection.insert(doc1);
transaction.commit();
}
}
```
--------------------------------
### Start and Commit Transaction on ObjectRepository (Dart)
Source: https://nitrite.dizitart.com/flutter-sdk/transaction/index
Illustrates the process of starting a transaction from a session, retrieving an `ObjectRepository` within that transaction, performing repository operations (like inserting an employee), and then committing the transaction to persist changes.
```dart
// start a transaction
var transaction = await session.beginTransaction();
// get a repository
var repository = await transaction.getRepository();
// perform operations on the repository
await repository.insert(employee);
// commit the transaction
await transaction.commit();
```
--------------------------------
### Create Nitrite Database Instance
Source: https://nitrite.dizitart.com/kotlin-sdk/database/index
Initializes a Nitrite database instance using a builder pattern. Configuration options can be provided within the lambda block. This is the primary entry point for creating a database.
```kotlin
var db = nitrite {
// database configuration
}
```
--------------------------------
### Create RocksDB Backed On-Disk Database
Source: https://nitrite.dizitart.com/java-sdk/database/index
Creates a Nitrite database persisted on disk using the RocksDB storage engine. Requires the RocksDBModule and specifies the file path for the database.
```java
RocksDBModule storeModule = RocksDBModule.withConfig()
.filePath("/path/to/my.db")
.build();
Nitrite db = Nitrite.builder()
.loadModule(storeModule)
.openOrCreate();
```
--------------------------------
### Start and Commit Transaction on NitriteCollection (Dart)
Source: https://nitrite.dizitart.com/flutter-sdk/transaction/index
Demonstrates how to manually start a transaction from a session, obtain a collection within that transaction, perform insert operations, and finally commit the transaction. This ensures data consistency for a series of operations.
```dart
var transaction = await session.beginTransaction();
// get a collection
var collection = await transaction.getCollection("test");
// perform operations on the collection
await collection.insert(doc1);
// commit the transaction
await transaction.commit();
```
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Untitled
No description
--------------------------------
### Open or Create File-Based Database
Source: https://nitrite.dizitart.com/java-sdk/database/index
Opens an existing file-based Nitrite database or creates a new one if it doesn't exist. This requires a configured StoreModule.
```java
Nitrite db = Nitrite.builder()
.loadModule(storeModule)
.openOrCreate();
```
--------------------------------
### Untitled
No description
--------------------------------
### Configure Import Options for Nitrite Database
Source: https://nitrite.dizitart.com/java-sdk/support/exchange/index
Shows how to create and configure `ImportOptions` for importing a Nitrite database. Key options include setting a `NitriteFactory` to create the `Nitrite` instance and an optional `JsonFactory` for JSON parsing. The example illustrates setting a `NitriteFactory` using a lambda expression.
```java
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.importer.ImportOptions;
import org.dizitart.no2.module.NitriteModule;
// Assume createDb() is a function that returns a Nitrite instance
// e.g., Nitrite createDb(String dbName) { return Nitrite.builder().filePath(dbName).open(); }
// create import options
ImportOptions importOptions = new ImportOptions();
// set the nitrite factory
importOptions.setNitriteFactory(() -> {
// Replace with your actual method to create a Nitrite instance
// For demonstration, creating a new database instance
return Nitrite.builder().filePath("new-test.db").open();
});
```
--------------------------------
### Get Repository Size (Dart)
Source: https://nitrite.dizitart.com/flutter-sdk/repository/other/index
Retrieves the number of entities in a repository. Returns a future integer representing the count.
```dart
int size = await productRepository.size;
```
--------------------------------
### Untitled
No description
--------------------------------
### Create a Simple Document in Kotlin
Source: https://nitrite.dizitart.com/kotlin-sdk/document/index
Demonstrates how to create a basic Nitrite document using the `documentOf` extension function in Kotlin. This function takes a variable number of string-to-any pairs to define the document's fields and values.
```kotlin
val document = documentOf("firstName" to "John", "lastName" to "Doe")
```
--------------------------------
### Untitled
No description
--------------------------------
### Create Empty Document in Dart
Source: https://nitrite.dizitart.com/flutter-sdk/document/index
Provides an example of creating an empty Nitrite document using the `emptyDocument()` function.
```dart
var document = emptyDocument();
```