Skip to content

Commit 7b9509f

Browse files
committed
2 parents 06b4117 + 2b60640 commit 7b9509f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Based on the installation path above.
6767
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
6868
```
6969

70-
2. Create a `src/store.js` file:
70+
2. Create a `store.js` file:
7171

7272
```js
7373
// Import Dexie.js
@@ -91,32 +91,39 @@ Based on the installation path above.
9191
export { db, sync }
9292
```
9393
94-
3. Use the database according to the [Dexie.js documentation](https://dexie.org/), example `src/main.(js|ts|jsx)` file:
94+
3. Use the database according to the [Dexie.js documentation](https://dexie.org/), example `main.js` file:
9595
9696
```js
9797
import { db } from './store'
9898
db.tasks.add({ title: 'New Task' }).then(
99-
db.tasks.where('$deleted').notEqual(1).toArray().then(console.log)
99+
db.tasks.where('$deleted').notEqual(1).reverse().sortBy('$created').then(console.log)
100100
)
101101
```
102102
103-
Run `npm run dev` and see the task list from `testdata.sql` being logged to the console.
103+
Run `npm run dev`, open http://localhost:5173 and see how the task list is logged to the console.
104+
105+
Open phpMyAdmin at http://localhost:8080, login with `root`:`root` and take a look at the database.
104106
105107
The required properties `id`, `userId`, `$created`, `$updated`, `$deleted` and `$synchronized` are set and updated automatically, you do not need to modify them manually. By default, UUIDv4 is used for new ids.
106108
107-
## Function Details
109+
When the user is authenticated with `login()`, new records will get the `userId` property automatically and all `read`, `list`, `update` and `delete` requests are limited to the users records (see [Multi Tenancy Documentation](https://github.com/mevdschee/php-crud-api#multi-tenancy-support)).
110+
111+
## Class Details
108112
109-
### useSync(endpoint)
113+
### Sync(endpoint)
110114
111115
Intializes the synchronization API.
112116
113117
- `endpoint`: `<string>`, *optional*, [PHP CRUD API](https://github.com/mevdschee/php-crud-api?tab=readme-ov-file#installation) endpoint, internal or external, default `/api.php`
114118
115119
```js
116-
const sync = useSync()
120+
import Sync from 'dexie-mysql-sync'
121+
const sync = new Sync()
117122
```
118123
119-
#### sync.add(table, path, options)
124+
## Function Details
125+
126+
### sync.add(table, path, options)
120127
121128
Starts the synchronization to and from remote. Multiple browser windows are supported.
122129
@@ -138,37 +145,37 @@ A local table can be synchronized with only one remote table.
138145
139146
A remote table can be synchronized with one or more local tables.
140147
141-
#### sync.emptyTable(table)
148+
### sync.emptyTable(table)
142149
143150
Removes all records from a local table without synchronizing them as deleted to the server.
144151
145152
- `table`: [Dexie.js Table](https://dexie.org/docs/Dexie/Dexie.%5Btable%5D)
146153
147-
#### sync.reset()
154+
### sync.reset()
148155
149156
Resets all synchronizations. All local and remote documents are synchronized again.
150157
151158
- `database`: [Dexie.js Database](https://dexie.org/docs/Dexie/Dexie)
152159
153-
#### sync.register(username, password)
160+
### sync.register(username, password)
154161
155162
Creates a new user.
156163
157-
#### sync.login(username, password)
164+
### sync.login(username, password)
158165
159166
Logs the user in, clears all local tables and resets the synchronization.
160167
161-
#### sync.password(username, password, newPassword)
168+
### sync.password(username, password, newPassword)
162169
163170
Updates the password of the user.
164171
165-
#### sync.user(callback)
172+
### sync.user(callback)
166173
167174
Returns the use details or null.
168175
169176
- `callback`: `<function>` *optional*, callback on any user change with user details or null
170177
171-
#### sync.logout()
178+
### sync.logout()
172179
173180
Logs the user out, clears all local tables and resets the synchronization.
174181

0 commit comments

Comments
 (0)