Skip to content

Commit

Permalink
fix: build with poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
voznik committed Mar 21, 2024
1 parent 75ec3f3 commit 65f562d
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 261 deletions.
56 changes: 43 additions & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,21 @@
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"args": ["${relativeFile}"],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"args": [
"${relativeFile}"
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"skipFiles": ["<node_internals>/**", "node_modules/**"],
"skipFiles": [
"<node_internals>/**",
"node_modules/**"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
Expand All @@ -87,20 +96,41 @@
},
//
{
"name": "Python: Streamlit",
"type": "python",
"request": "launch",
"module": "streamlit",
"args": ["run", "${file}", "--server.headless=true", "--browser.gatherUsageStats=false"],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"console": "integratedTerminal"
"name": "Python: Debug Test",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"args": [
"${file}"
],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"console": "integratedTerminal"
},
{
"name": "Python: Debug Streamlit",
"type": "debugpy",
"request": "launch",
"module": "streamlit",
"args": [
"run",
"${file}",
"--server.headless=true",
"--browser.gatherUsageStats=false"
],
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"console": "integratedTerminal"
}
],
"inputs": [
{
"options": ["rxdb", "kinto"],
"options": [
"rxdb",
"kinto"
],
"id": "libName",
"type": "pickString",
"default": "rxdb",
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ import { getRxDatabaseCreator } from '@ngx-odm/rxdb/config';
multiInstance: true, // <- multiInstance (optional, default: true)
ignoreDuplicate: false,
options: {
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
storageType: 'dexie|memory', // <- storageType (optional, use if you want defaults provided automatically)
dumpPath: 'assets/dump.json', // path to datbase dump file (optional)
},
Expand Down Expand Up @@ -106,7 +112,7 @@ const todoCollectionConfig: RxCollectionCreatorExtended = {
})
export class TodosModule {
constructor(
@Inject(NgxRxdbCollectionService) private collectionService: NgxRxdbCollection<Todo>
@Inject(RXDB_COLLECTION) private collectionService: RxDBCollectionService<Todo>
) {
this.collectionService.sync(); // INFO: collection is ready
}
Expand All @@ -116,11 +122,13 @@ export class TodosModule {
### In your `FeatureService`

```typescript
import { RXDB_COLLECTION } from '@ngx-odm/rxdb';
import { RxDBCollectionService } from '@ngx-odm/rxdb/collection';

@Injectable()
export class TodosService {
private collectionService: NgxRxdbCollection<Todo> = inject<NgxRxdbCollection<Todo>>(
NgxRxdbCollectionService
);
private collectionService: RxDBCollectionService<Todo> =
inject<RxDBCollectionService<Todo>>(RXDB_COLLECTION);
// store & get filter as property of a `local` document
filter$ = this.collectionService
.getLocal('local', 'filterValue')
Expand Down Expand Up @@ -177,6 +185,12 @@ export const appConfig: ApplicationConfig = {
multiInstance: true,
ignoreDuplicate: false,
storage: getRxStorageDexie(),
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
})
),
],
Expand Down
31 changes: 26 additions & 5 deletions packages/rxdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Demo

![Example Screencast](https://github.com/voznik/ngx-odm/blob/master/examples/screencast.gif?raw=true)
![Example Screencast](examples/screencast.gif)

[demo](https://voznik.github.io/ngx-odm/) - based on TodoMVC

Expand Down Expand Up @@ -63,6 +63,12 @@ import { getRxDatabaseCreator } from '@ngx-odm/rxdb/config';
multiInstance: true, // <- multiInstance (optional, default: true)
ignoreDuplicate: false,
options: {
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
storageType: 'dexie|memory', // <- storageType (optional, use if you want defaults provided automatically)
dumpPath: 'assets/dump.json', // path to datbase dump file (optional)
},
Expand Down Expand Up @@ -106,7 +112,7 @@ const todoCollectionConfig: RxCollectionCreatorExtended = {
})
export class TodosModule {
constructor(
@Inject(NgxRxdbCollectionService) private collectionService: NgxRxdbCollection<Todo>
@Inject(RXDB_COLLECTION) private collectionService: RxDBCollectionService<Todo>
) {
this.collectionService.sync(); // INFO: collection is ready
}
Expand All @@ -116,11 +122,13 @@ export class TodosModule {
### In your `FeatureService`

```typescript
import { RXDB_COLLECTION } from '@ngx-odm/rxdb';
import { RxDBCollectionService } from '@ngx-odm/rxdb/collection';

@Injectable()
export class TodosService {
private collectionService: NgxRxdbCollection<Todo> = inject<NgxRxdbCollection<Todo>>(
NgxRxdbCollectionService
);
private collectionService: RxDBCollectionService<Todo> =
inject<RxDBCollectionService<Todo>>(RXDB_COLLECTION);
// store & get filter as property of a `local` document
filter$ = this.collectionService
.getLocal('local', 'filterValue')
Expand Down Expand Up @@ -177,6 +185,12 @@ export const appConfig: ApplicationConfig = {
multiInstance: true,
ignoreDuplicate: false,
storage: getRxStorageDexie(),
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
})
),
],
Expand Down Expand Up @@ -247,7 +261,14 @@ By using this module you can simplify your work with RxDB in Angular application
- optionally provide syncronization with remote db (CouchDB, Kinto etc.) as DB options
- Automatically initialize RxCollection for each _lazy-loaded Feature module / standalone component_ with config
- Work with documents via _NgxRxdbCollectionService_ with unified methods instead of using _RxCollection_ directly (though you still have access to _RxCollection_ and _RxDatabase_ instance)
- simple methods to work database & documents (with queries)
- simple methods to work with local documents
- simple methods to work with attachments
- simple replication sync initialization
- Work with signals and entities with `@ngrx/signals` and `@ngrx/entity` (optionally _zoneless_) (see [example](examples/standalone/src/app/todos/todos.store.ts))
- Persist collection query ([mango-query-syntax](https://github.com/cloudant/mango)) in URL with new plugin `query-params-plugin` (in demo, set localStorage `_ngx_rxdb_queryparams` )
- provide Observable of current URL (automatically for Angular)
- simple methods to set or patch filter, sort, limit, skip

<!-- ## Diagrams
Expand Down
182 changes: 180 additions & 2 deletions packages/streamlit-rxdb-dataframe/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,183 @@
<!-- An exception thrown inside a promise will not be caught by a nesting try block due to the asynchronous nature of execution.
# streamlit-rxdb-dataframe

Promises are designed to propagate errors to the next error handler or catch() block in the promise chain. Promises are asynchronous and operate outside of the normal call stack. When a Promise is created, it is added to the microtask queue, which is processed after the current call stack has completed. This means that the try-catch block surrounding the Promise will have already completed by the time the Promise is resolved or rejected. Therefore, any error occurring within the Promise will not be caught by the try-catch block.
Custom `streamlit` component connecting local browser `indexedDB` database as `RxDB` collection as `dataframe`

## Demo

[demo](https://st-rxdb-dataframe.streamlit.app/) - based on TodoMVC

![Example Screencast](https://github.com/voznik/ngx-odm/blob/master/packages/streamlit-rxdb-dataframe/screencast.gif?raw=true)

## Usage

### Provide JSONSchema

<details>
<summary>JSONSchema</summary>

```json
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Todo",
"description": "Todo Schema",
"required": ["id", "title", "createdAt"],
"version": 0,
"properties": {
"id": {
"type": "string",
"format": "uuid",
"title": "Id",
"pattern": "^(.*)$",
"maxLength": 36,
"readOnly": true
},
"title": {
"type": "string",
"title": "Title",
"minLength": 3
},
"completed": {
"type": "boolean",
"title": "Done"
},
"createdAt": {
"type": "string",
"title": "Created Date",
"format": "date-time",
"readOnly": true
},
"last_modified": {
"type": "integer",
"format": "time",
"title": "Last Modified Date"
}
},
"__indexes": ["createdAt"],
"primaryKey": "id",
"attachments": {
"encrypted": false
}
}
```

</details>

### Provide Collection Config and use streamlit dataframe, data_editor or table

```python

todoSchema: Dict = json.load(open(os.path.join(data_dir, "todo.schema.json")))
# initial_docs: List = json.load(open(os.path.join(data_dir, "col.dump.json")))["docs"]
collection_config = {
"name": "todo",
"schema": todoSchema, # to auto load schema from remote url pass None
"localDocuments": True,
"options": {
# 'schemaUrl': 'assets/data/todo.schema.json',
# "initialDocs": initial_docs,
},
}

def on_change_dataframe(rxdb_state: RxDBSessionState):
print("RxDBDataframe component on_change call")
print("collection.info()", rxdb_state.info)
print("dataframe.head()", rxdb_state.dataframe.head())

df = rxdb_dataframe(
collection_config,
query=None,
with_rev=False,
on_change=on_change_dataframe,
)
st.dataframe(
df,
use_container_width=True,
hide_index=True,
column_config=st.session_state["rxdb"]["column_config"],
column_order=["title", "completed", "createdAt"],
)
```

## Run & Build

### Run

```bash
cd packages/streamlit-rxdb-dataframe/
poetry run streamlit run example.py
```

### Build

```bash
poetry build -o ../../dist/packages/streamlit-rxdb-dataframe
```

### Publish

```bash
poetry publish -r test-pypi --dist-dir ../../dist/packages/streamlit-rx
db-dataframe
```

<!--
# TODO: Add form to construct RxQuery
# query_container = st.container()
# with query_container:
# to_filter_columns = st.multiselect(
# "Filter dataframe on",
# df.columns,
# key=f"{prefix}_multiselect",
# )
# filters: Dict[str, Any] = dict()
# for column in to_filter_columns:
# left, right = st.columns((1, 20))
# # Treat columns with < 10 unique values as categorical
# if is_categorical_dtype(df[column]) or df[column].nunique() < 10:
# left.write("↳")
# filters[column] = right.multiselect(
# f"Values for {column}",
# df[column].unique(),
# default=list(df[column].unique()),
# key=f"{prefix}_{column}",
# )
# df = df[df[column].isin(filters[column])]
# elif is_numeric_dtype(df[column]):
# left.write("↳")
# _min = float(df[column].min())
# _max = float(df[column].max())
# step = (_max - _min) / 100
# filters[column] = right.slider(
# f"Values for {column}",
# _min,
# _max,
# (_min, _max),
# step=step,
# key=f"{prefix}_{column}",
# )
# df = df[df[column].between(*filters[column])]
# elif is_datetime64_any_dtype(df[column]):
# left.write("↳")
# filters[column] = right.date_input(
# f"Values for {column}",
# value=(
# df[column].min(),
# df[column].max(),
# ),
# key=f"{prefix}_{column}",
# )
# if len(filters[column]) == 2:
# filters[column] = tuple(map(pd.to_datetime, filters[column])) # noqa: E501
# start_date, end_date = filters[column]
# df = df.loc[df[column].between(start_date, end_date)]
# else:
# left.write("↳")
# filters[column] = right.text_input(
# f"Pattern in {column}",
# key=f"{prefix}_{column}",
# )
# if filters[column]:
# print(filters[column])
-->
Loading

0 comments on commit 65f562d

Please sign in to comment.