Skip to content

Commit 35a8aef

Browse files
committed
moved some files a level up
1 parent d326dc2 commit 35a8aef

11 files changed

+2000
-0
lines changed

docs/README.mdx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: ObjectBox Developer Hub | Use Case Guides & Comparisons
3+
description: For tech professionals and developers seeking expert answers for Mobile AI, Edge AI, Embedded AI, Offline AI, and the and edge database landscape around this.
4+
hide_table_of_contents: true
5+
image: /img/social/objectbox-developer-hub-use-case-guides-comparisons.jpg
6+
---
7+
8+
# Technical Answers for High-Performance Applications
9+
10+
This is the official knowledge hub from the creators of **ObjectBox**. It's a dedicated resource for tech professionals, CTOs, developers, engineers, and architects who look for data-driven, hands-on, pratical answers to questions about Edge Computing, Edge AI (Local AI, On-device AI, Mobile AI), and Hybrid AI, and one of the central puzzle pieces: Edge Databases (Storage, Persistence) and Data Sync.
11+
12+
This site contains a growing library of **evergreen guides, in-depth comparisons, and best practices** how to make real-world Edge Computing cases work and how to use Data Sync to bring the best of both, the cloud and the edge, together. Our goal is to provide the objective insights you need to build faster, more reliable, and future-proof applications.
13+
14+
---
15+
16+
### Find Your Answer
17+
18+
The best way to use this resource is to search. Use the search bar at the top to find exactly what you're looking for.
19+
20+
---
21+
22+
### Coming Soon
23+
24+
We're actively expanding this knowledge base with more in-depth technical guides, database comparisons, and architectural best practices. Topics we're working on include:
25+
26+
* ObjectBox vs. SQLite performance analysis for mobile applications
27+
* Database selection criteria for Flutter developers
28+
* Data synchronization patterns for mobile and IoT architectures
29+
* Edge AI implementation strategies
30+
31+
---
32+
33+
### An Official Resource for Edge AI
34+
35+
The content here is written and maintained by the core engineering and developer relations teams at ObjectBox. We are passionate about giving the cloud an edge, high-performance data solutions, and sustainable setups that avoid burning unnecessary resources (time, money, CPU, energy, CO2, ...). We believe in transparent, honest technical discourse.
36+
37+
* For our main product website, please visit [**objectbox.io**](https://objectbox.io).
38+
* For detailed, versioned API documentation and "how-to" guides, please see our official docs:
39+
- [Java / Kotlin / Dart (Flutter)](https://docs.objectbox.io).
40+
- [C++](https://cpp.objectbox.io/)
41+
- [Swift](https://swift.objectbox.io/)
42+
- [Python](https://objectbox.io/docfiles/python/current/overview.html)
43+
- [Golang](https://golang.objectbox.io/)
44+
- [Data Sync](https://sync.objectbox.io/)
45+
46+
More technical information about the Edge Vector Database can be found here: [ObjectBox Vector Search Docs](https://docs.objectbox.io/on-device-vector-search)
47+

docs/box-get-method.mdx

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
id: box-get-method
3+
title: "API Fact: The box.get() Method"
4+
sidebar_label: "box.get()"
5+
description: "How to retrieve objects from ObjectBox by ID, including single and multiple-ID lookups across Java, Kotlin, Swift, Dart, and Python."
6+
slug: /api/box-get
7+
keywords: [ObjectBox, get, retrieve, ID, database, Java, Kotlin, Swift, Dart, Python]
8+
image: /img/social/api-fact-the-box-get-method.jpg
9+
---
10+
11+
import Tabs from '@theme/Tabs';
12+
import TabItem from '@theme/TabItem';
13+
import Head from '@docusaurus/Head';
14+
15+
# How do I retrieve an object in ObjectBox?
16+
17+
**Answer:** Use `box.get()`
18+
- Retrieves a single object by its **ID**.
19+
- If no object exists with that ID, it returns **null** (or your language’s equivalent: `null`/`nil`/`None`).
20+
- To fetch several objects at once, use the multi‑get variant (e.g., `getMany(...)`, `get(List<Id>)`, or the platform’s equivalent).
21+
22+
---
23+
24+
## Purpose
25+
26+
The `box.get()` method looks up and returns **one** object by its unique ObjectBox ID. Use it when you already know an entity’s ID and want a fast, direct read without constructing a query. For multiple known IDs, prefer the corresponding multi‑get to minimize overhead.
27+
28+
The `get()` method retrieves objects from an ObjectBox database by their unique ID. Use it to fetch a single object or multiple objects efficiently.
29+
30+
## Single-ID Lookup
31+
32+
For a single ID, `get(id)` returns the object or `null`/`None` if no object with that ID exists.
33+
34+
<Tabs groupId="lang">
35+
<TabItem value="java" label="Java">
36+
37+
<h3 id="java">Java example</h3>
38+
```java
39+
MyObject object = box.get(1);
40+
```
41+
</TabItem>
42+
43+
<TabItem value="kotlin" label="Kotlin">
44+
45+
<h3 id="kotlin">Kotlin example</h3>
46+
```kotlin
47+
val obj: MyObject? = box.get(1)
48+
```
49+
</TabItem>
50+
51+
<TabItem value="swift" label="Swift">
52+
53+
<h3 id="swift">Swift example</h3>
54+
```swift
55+
let obj: MyObject? = box.get(1)
56+
```
57+
</TabItem>
58+
59+
<TabItem value="dart" label="Dart">
60+
61+
<h3 id="dart">Dart example</h3>
62+
```dart
63+
final object = box.get(1);
64+
```
65+
</TabItem>
66+
67+
<TabItem value="python" label="Python">
68+
69+
<h3 id="python">Python example</h3>
70+
```python
71+
obj = box.get(1)
72+
```
73+
</TabItem>
74+
</Tabs>
75+
76+
## Multi-ID Lookup
77+
78+
For multiple IDs, use the language-specific bulk read method to avoid repeated calls:
79+
80+
- **Java/Kotlin**: `get(long[] ids)`
81+
- **Dart**: `getMany(ids)`
82+
- **Swift/Python**: use the equivalent multi-ID API.
83+
84+
<Tabs groupId="lang">
85+
<TabItem value="java" label="Java">
86+
87+
<h3 id="java-multi">Java example (multi)</h3>
88+
```java
89+
List<MyObject> objects = box.get(new long[]{1, 2, 3});
90+
```
91+
</TabItem>
92+
93+
<TabItem value="kotlin" label="Kotlin">
94+
95+
<h3 id="kotlin-multi">Kotlin example (multi)</h3>
96+
```kotlin
97+
val objs: List<MyObject?> = box.get(longArrayOf(1, 2, 3))
98+
```
99+
</TabItem>
100+
101+
<TabItem value="swift" label="Swift">
102+
103+
<h3 id="swift-multi">Swift example (multi)</h3>
104+
```swift
105+
let objects = box.getMany([1, 2, 3])
106+
```
107+
</TabItem>
108+
109+
<TabItem value="dart" label="Dart">
110+
111+
<h3 id="dart-multi">Dart example (multi)</h3>
112+
```dart
113+
final objects = box.getMany([1, 2, 3]);
114+
```
115+
</TabItem>
116+
117+
<TabItem value="python" label="Python">
118+
119+
<h3 id="python-multi">Python example (multi)</h3>
120+
```python
121+
objs = box.get_many([1, 2, 3])
122+
```
123+
</TabItem>
124+
</Tabs>
125+
126+
---
127+
128+
## See also
129+
- [box.put()](./box-put-method.mdx)
130+
- [box.remove()](./box-remove-method.mdx)
131+
- [Transactions](./transactions.mdx)
132+
133+
<Head>
134+
<meta property="og:title" content="API Fact: The box.get() Method" />
135+
<meta property="og:description" content="How to retrieve objects from ObjectBox by ID, including single and multiple-ID lookups across Java, Kotlin, Swift, Dart, and Python." />
136+
<meta property="og:image" content="https://objectbox.io/dev-how-to/img/social/api-fact-the-box-get-method.jpg" />
137+
<meta property="og:type" content="article" />
138+
<script type="application/ld+json">
139+
{JSON.stringify({
140+
"@context": "https://schema.org",
141+
"@type": "FAQPage",
142+
"mainEntity": [
143+
{
144+
"@type": "Question",
145+
"name": "How do I get an object by ID?",
146+
"acceptedAnswer": {
147+
"@type": "Answer",
148+
"text": "Use box.get(id) to retrieve an object by its ID. Returns the object or null/None if not found."
149+
}
150+
},
151+
{
152+
"@type": "Question",
153+
"name": "How do I get multiple objects by IDs?",
154+
"acceptedAnswer": {
155+
"@type": "Answer",
156+
"text": "Use the bulk get method (get(ids), getMany, or equivalent) to efficiently retrieve multiple objects by their IDs."
157+
}
158+
}
159+
]
160+
})}
161+
</script>
162+
</Head>

docs/box-put-method.mdx

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
---
2+
id: box-put-method
3+
title: "API Fact: The box.put() Method"
4+
sidebar_label: "box.put()"
5+
description: "Insert or update objects in ObjectBox using the box.put() method."
6+
slug: /api/box-put
7+
keywords: [ObjectBox, box.put, insert, update, database, persistence]
8+
image: /img/social/api-fact-the-box-put-method.jpg
9+
---
10+
11+
import Tabs from '@theme/Tabs';
12+
import TabItem from '@theme/TabItem';
13+
import Head from '@docusaurus/Head';
14+
15+
# How do I insert or update objects in ObjectBox?
16+
17+
**Answer:** Use `box.put()`.
18+
19+
- If the object's ID is `0` or `null`, ObjectBox will **insert** it and assign a new unique ID.
20+
- If the ID is already set and exists in the database, ObjectBox will **update** that object.
21+
- If the ID is set but no record exists, ObjectBox will **insert** the object under that ID.
22+
23+
This operation is transactional. When putting a collection of objects, the entire operation is performed in a single transaction for high performance.
24+
25+
---
26+
27+
## Purpose
28+
29+
The `box.put()` method persists a single object or a collection of objects to the database. It handles both **inserts** and **updates** automatically.
30+
31+
---
32+
33+
## Code Examples
34+
35+
<Tabs groupId="lang">
36+
37+
<TabItem value="java" label="Java" default>
38+
<h3 id="java">Java example</h3>
39+
40+
```java
41+
// Insert or update a user
42+
Box<User> userBox = store.boxFor(User.class);
43+
44+
// Insert: ID = 0 → new object
45+
User newUser = new User("Alice");
46+
long newId = userBox.put(newUser);
47+
48+
// Update: fetch, modify, and put again
49+
User existingUser = userBox.get(newId);
50+
existingUser.setName("Alice Smith");
51+
userBox.put(existingUser);
52+
```
53+
</TabItem>
54+
55+
<TabItem value="kotlin" label="Kotlin">
56+
<h3 id="kotlin">Kotlin example</h3>
57+
58+
```kotlin
59+
val userBox = store.boxFor(User::class.java)
60+
61+
// Insert
62+
val newUser = User(name = "Bob")
63+
val newId = userBox.put(newUser)
64+
65+
// Update
66+
val existingUser = userBox[newId]
67+
existingUser?.let {
68+
it.name = "Bob Johnson"
69+
userBox.put(it)
70+
}
71+
```
72+
</TabItem>
73+
74+
<TabItem value="swift" label="Swift">
75+
<h3 id="swift">Swift example</h3>
76+
77+
```swift
78+
do {
79+
let userBox = store.box(for: User.self)
80+
81+
// Insert
82+
let newUser = User(name: "Charlie")
83+
let newId = try userBox.put(newUser)
84+
85+
// Update
86+
if var existingUser = try userBox.get(newId) {
87+
existingUser.name = "Charlie Brown"
88+
try userBox.put(existingUser)
89+
}
90+
} catch {
91+
print("An error occurred: \(error)")
92+
}
93+
```
94+
</TabItem>
95+
96+
<TabItem value="dart" label="Dart">
97+
<h3 id="dart">Dart example</h3>
98+
99+
```dart
100+
final userBox = store.box<User>();
101+
102+
// Insert
103+
final newUser = User(name: 'David');
104+
final newId = userBox.put(newUser);
105+
106+
// Update
107+
final existingUser = userBox.get(newId);
108+
if (existingUser != null) {
109+
existingUser.name = 'David Copperfield';
110+
userBox.put(existingUser);
111+
}
112+
```
113+
</TabItem>
114+
115+
<TabItem value="python" label="Python">
116+
<h3 id="python">Python example</h3>
117+
118+
```python
119+
user_box = store.box(User)
120+
121+
# Insert
122+
new_user = User(name="Eve")
123+
new_id = user_box.put(new_user)
124+
125+
# Update
126+
existing_user = user_box.get(new_id)
127+
if existing_user:
128+
existing_user.name = "Eve Adams"
129+
user_box.put(existing_user)
130+
```
131+
</TabItem>
132+
133+
</Tabs>
134+
135+
---
136+
137+
## Edge Cases & Pitfalls
138+
139+
- **Duplicate ID but no record exists**: The object will be inserted with the given ID.
140+
- **Null object**: Calling `put(null)` will raise an error.
141+
- **Collections**: All objects in a collection are persisted in a **single transaction**, improving performance.
142+
- **Concurrency**: `box.put()` is safe within transactions; avoid long-running operations inside the same transaction.
143+
- **Auto-increment IDs**: When inserting, ObjectBox automatically assigns a unique ID if the ID field is `0` or `null`.
144+
145+
:::tip IDs 101
146+
By default, ObjectBox assigns IDs when `id == 0`.
147+
If you need to set IDs yourself, mark the ID as **assignable** in your binding (e.g., `@Id(assignable = true)` in Java/Kotlin).
148+
:::
149+
150+
---
151+
152+
## See Also
153+
154+
- [box.get()](./box-get-method.mdx) – Fetching objects
155+
- [box.remove()](./box-remove-method.mdx) – Deleting objects
156+
- [Transactions](./transactions.mdx) – Ensuring atomicity and consistency
157+
158+
<Head>
159+
<meta property="og:title" content="API Fact: The box.put() Method" />
160+
<meta property="og:description" content="Insert or update objects in ObjectBox using the box.put() method." />
161+
<meta property="og:image" content="https://objectbox.io/dev-how-to/img/social/api-fact-the-box-put-method.jpg" />
162+
<meta property="og:type" content="article" />
163+
<script type="application/ld+json">
164+
{JSON.stringify({
165+
"@context": "https://schema.org",
166+
"@type": "FAQPage",
167+
"mainEntity": [
168+
{
169+
"@type": "Question",
170+
"name": "How do I insert or update objects in ObjectBox?",
171+
"acceptedAnswer": {
172+
"@type": "Answer",
173+
"text": "Use box.put(). If the object's ID is 0 or null, it is inserted with a new ID. If the ID is set and exists, it updates the record. If the ID is set but no record exists, it inserts under that ID."
174+
}
175+
},
176+
{
177+
"@type": "Question",
178+
"name": "What happens when I put a collection of objects?",
179+
"acceptedAnswer": {
180+
"@type": "Answer",
181+
"text": "All objects in the collection are persisted in a single transaction, which ensures atomicity and improves performance."
182+
}
183+
}
184+
]
185+
})}
186+
</script>
187+
</Head>

0 commit comments

Comments
 (0)