Skip to content

Commit 4a7b1f9

Browse files
authored
fix(dx): alias schema to lookup helpers (#72)
1 parent b1201ed commit 4a7b1f9

File tree

25 files changed

+399
-349
lines changed

25 files changed

+399
-349
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,18 @@ You can clone and run our React code examples [here](examples/).
5353

5454
### `HomebaseProvider`
5555

56-
The HomebaseProvider wraps your React app and makes a relational database accessible to all of your components. Configure it with `schema` and `initialData`.
56+
The HomebaseProvider wraps your React app and makes a relational database accessible to all of your components. Configure it with `lookupHelpers` and `initialData`.
5757

5858
```js
5959
import { HomebaseProvider, useEntity, useTransact, useQuery } from 'homebase-react'
6060

6161
const config = {
62-
// Schema is not a type system,
63-
// it's a way to simplify relational queries at query time.
64-
// The schema currently supported is:
62+
// Lookup helpers simplify relational queries at query time.
63+
// The helpers currently supported are:
6564
// `type: 'ref'` which is a relationship and
6665
// `unique: 'identity` which enforces a uniqueness constraint
6766
// and lets you lookup entities by their unique attributes.
68-
schema: {
67+
lookupHelpers: {
6968
todo: {
7069
project: { type: 'ref', cardinality: 'one' },
7170
name: { unique: 'identity' }
@@ -174,7 +173,7 @@ todos
174173

175174
This hook returns the current database client with some helpful functions for syncing data with a backend.
176175

177-
- `client.dbToString()` serializes the whole db including the schema to a string
176+
- `client.dbToString()` serializes the whole db including the lookupHelpers to a string
178177
- `client.dbFromString('a serialized db string')` replaces the current db
179178
- `client.dbToDatoms()` returns an array of all the facts aka datoms saved in the db
180179
- datoms are the smallest unit of data in the database, like a key value pair but better

docs/0300|Tutorial.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,21 @@ import { HomebaseProvider, useTransact, useQuery, useEntity } from 'homebase-rea
1212

1313
export const App = () => {
1414
return (
15-
<HomebaseProvider config={{ schema, initialData }}>
15+
<HomebaseProvider config={{ lookupHelpers, initialData }}>
1616
<Todos/>
1717
</HomebaseProvider>
1818
)
1919
}
2020
```
2121

22-
## Schema
22+
## Lookup Helpers
2323

2424
Unlike other state managers, Homebase does not try to create yet another design pattern for state. Instead, we store state in a way we already know and love: as a relational graph database.
2525

26-
Like any good database we support schema on read.
27-
28-
At the moment schema is only for relationships and uniqueness constraints. It does not support typing of attributes, e.g. strings, integers, dates. We're working on adding the option to opt into schema on write support. This will provide basic type checking like you see in SQL.
26+
Lookup helpers make relationships and uniqueness constraints something you declare once and then never need to worry about again. Subsequent queries and transactions will take these properties into account so you never have to write a join query.
2927

3028
```jsx
31-
const schema = {
29+
const lookupHelpers = {
3230
project: {
3331
name: {
3432
unique: 'identity'
@@ -91,7 +89,7 @@ And now we're ready to go. 🚀
9189

9290
```jsx
9391
const config = {
94-
schema,
92+
lookupHelpers,
9593
initialData
9694
}
9795
```
@@ -348,10 +346,9 @@ export const App = () => {
348346
}
349347

350348
const config = {
351-
// Schema is only used to enforce
349+
// Lookup helpers are used to enforce
352350
// unique constraints and relationships.
353-
// It is not a type system, yet.
354-
schema: {
351+
lookupHelpers: {
355352
project: { name: { unique: 'identity' } },
356353
todo: {
357354
// refs are relationships

docs/0400|API.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
## `HomebaseProvider`
22

3-
The HomebaseProvider wraps your React app and makes a relational database accessible to all of your components. Configure it with `schema` and `initialData`.
3+
The HomebaseProvider wraps your React app and makes a relational database accessible to all of your components. Configure it with `lookupHelpers` and `initialData`.
44

55
```js
66
import { HomebaseProvider, useEntity, useTransact, useQuery } from 'homebase-react'
77

88
const config = {
9-
// Schema is not a type system,
10-
// it's a way to simplify relational queries at query time.
11-
// The schema currently supported is:
9+
// Lookup helpers are a way to simplify relational queries at query time.
10+
// The helpers currently supported are:
1211
// `type: 'ref'` which is a relationship and
1312
// `unique: 'identity` which enforces a uniqueness constraint
1413
// and lets you lookup entities by their unique attributes.
15-
schema: {
14+
lookupHelpers: {
1615
todo: {
1716
project: { type: 'ref', cardinality: 'one' },
1817
name: { unique: 'identity' }
@@ -121,7 +120,7 @@ todos
121120

122121
This hook returns the current database client with some helpful functions for syncing data with a backend.
123122

124-
- `client.dbToString()` serializes the whole db including the schema to a string
123+
- `client.dbToString()` serializes the whole db including the lookupHelpers to a string
125124
- `client.dbFromString('a serialized db string')` replaces the current db
126125
- `client.dbToDatoms()` returns an array of all the facts aka datoms saved in the db
127126
- datoms are the smallest unit of data in the database, like a key value pair but better
@@ -141,7 +140,7 @@ Arrays and arbitrary JSON are partially supported for convenience. However in mo
141140

142141
```js
143142
const config = {
144-
schema: {
143+
lookupHelpers: {
145144
company: {
146145
numbers: { type: 'ref', cardinality: 'many' },
147146
projects: { type: 'ref', cardinality: 'many' },

examples/counter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@testing-library/jest-dom": "^5.11.4",
77
"@testing-library/react": "^11.1.0",
88
"@testing-library/user-event": "^12.1.10",
9-
"homebase-react": "^0.1.0",
9+
"homebase-react": "latest",
1010
"react": "^17.0.1",
1111
"react-dom": "^17.0.1",
1212
"react-scripts": "4.0.0",

examples/counter/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5348,10 +5348,10 @@ hmac-drbg@^1.0.0:
53485348
minimalistic-assert "^1.0.0"
53495349
minimalistic-crypto-utils "^1.0.1"
53505350

5351-
homebase-react@^0.1.0:
5352-
version "0.1.0"
5353-
resolved "https://registry.yarnpkg.com/homebase-react/-/homebase-react-0.1.0.tgz#e27a5b6bf6511b61cdc27b8b0ada31483bd1d997"
5354-
integrity sha512-q/+AiV8hVda/nYZ2oPstCyZJ+AjIDQsRGuTxZhBfl/Ew7aRCrNvBE3SI+ZWy9Qa6wTOC6e9qG3azgbLTLNIQxQ==
5351+
homebase-react@latest:
5352+
version "0.5.2"
5353+
resolved "https://registry.yarnpkg.com/homebase-react/-/homebase-react-0.5.2.tgz#27dc72989921f79174584dc557a488a20b930543"
5354+
integrity sha512-cJNcmsEbDg0F/fhSkUfe3lJ/tqhgOk/rHE7iC6zoUah9xufuFfNTwaxaArqdyF4m3SxWASCA4DznKYXFUZs9vQ==
53555355

53565356
hoopy@^0.1.4:
53575357
version "0.1.4"

examples/roam/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"autoprefixer": "^9",
1515
"firebase": "^8.2.6",
1616
"firebaseui": "^4.7.3",
17-
"homebase-react": "^0.5.1",
17+
"homebase-react": "latest",
1818
"lodash": "^4.17.20",
1919
"nanoid": "^3.1.20",
2020
"postcss": "^7",

examples/roam/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const NotLoggedInBanner = () => {
250250
}
251251

252252
const config = {
253-
schema: {
253+
lookupHelpers: {
254254
block: {
255255
uid: { unique: 'identity' },
256256
title: { unique: 'identity' },

examples/roam/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6298,7 +6298,7 @@ hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.1.0:
62986298
dependencies:
62996299
react-is "^16.7.0"
63006300

6301-
homebase-react@^0.5.1:
6301+
homebase-react@latest:
63026302
version "0.5.2"
63036303
resolved "https://registry.yarnpkg.com/homebase-react/-/homebase-react-0.5.2.tgz#27dc72989921f79174584dc557a488a20b930543"
63046304
integrity sha512-cJNcmsEbDg0F/fhSkUfe3lJ/tqhgOk/rHE7iC6zoUah9xufuFfNTwaxaArqdyF4m3SxWASCA4DznKYXFUZs9vQ==

examples/todo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@testing-library/jest-dom": "^5.11.4",
77
"@testing-library/react": "^11.1.0",
88
"@testing-library/user-event": "^12.1.10",
9-
"homebase-react": "^0.1.1",
9+
"homebase-react": "latest",
1010
"react": "^17.0.1",
1111
"react-dom": "^17.0.1",
1212
"react-scripts": "4.0.0",

examples/todo/src/App.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { HomebaseProvider, useEntity, useQuery, useTransact } from 'homebase-react'
12
import React from 'react'
2-
import { HomebaseProvider, useEntity, useTransact, useQuery } from 'homebase-react'
33
import './App.css'
44

55
export default function App() {
@@ -11,10 +11,9 @@ export default function App() {
1111
}
1212

1313
const config = {
14-
// Schema is only used to enforce
14+
// Lookup helpers are used to enforce
1515
// unique constraints and relationships.
16-
// It is not a type system, yet.
17-
schema: {
16+
lookupHelpers: {
1817
project: { name: { unique: 'identity' } },
1918
todo: {
2019
// refs are relationships

0 commit comments

Comments
 (0)