Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: complex docs (properties that are arrays or objects) #14

Merged
merged 2 commits into from
Aug 7, 2023

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Aug 4, 2023

SQLite can only store numbers (INTEGER or REAL) or strings (TEXT): https://www.sqlite.org/datatype3.html
Nullable fields are set to NULL if missing.

In Mapeo Core we use Drizzle and custom fields to map JSONSchema types to SQLite types and back. This module needs to do the same.

I initially attempted to do this by integrating Drizzle into here, but that led to a 15x slowdown and issues with Drizzle. This PR instead does the conversion based on incoming data type and the column type read from the DB schema.

Because we use prepared statements, we need to pass a value for every property (even optional props), therefore the transform does:

  • Missing props that are NOT NULL are set to the default value (null if no default set)
  • Boolean props are set to 1 (true) or 0 (false) in an integer collumn
  • Any array or object is JSON.stringify'd.

The indexer does not do reads, so it's only writes that matter.

This should match the transform done in mapeo core when reading from the
db, so that the read documents have the same shape/type as the docs
going in
@gmaclennan gmaclennan self-assigned this Aug 4, 2023
@gmaclennan gmaclennan changed the base branch from main to fix/column-names August 4, 2023 22:29
gmaclennan added a commit to digidem/comapeo-core that referenced this pull request Aug 5, 2023
Depends on:

- [ ] digidem/mapeo-sqlite-indexer#11
- [ ] digidem/mapeo-sqlite-indexer#14

Makes more sense to e2e test rather than unit test, which depends on
the new DataType class, which is next up.
gmaclennan added a commit to digidem/comapeo-core that referenced this pull request Aug 7, 2023
Depends on:

- [ ] digidem/mapeo-sqlite-indexer#11
- [ ] digidem/mapeo-sqlite-indexer#14

Makes more sense to e2e test rather than unit test, which depends on
the new DataType class, which is next up.
@gmaclennan gmaclennan changed the title Feat/complex-docs feat: complex docs (properties that are arrays or objects) Aug 7, 2023
Base automatically changed from fix/column-names to main August 7, 2023 18:46
@gmaclennan gmaclennan merged commit 0d27840 into main Aug 7, 2023
@gmaclennan gmaclennan deleted the feat/complex-docs branch August 7, 2023 18:50
gmaclennan added a commit to digidem/comapeo-core that referenced this pull request Aug 7, 2023
Depends on:

- [ ] digidem/mapeo-sqlite-indexer#11
- [ ] digidem/mapeo-sqlite-indexer#14

Makes more sense to e2e test rather than unit test, which depends on
the new DataType class, which is next up.
gmaclennan added a commit to digidem/comapeo-core that referenced this pull request Aug 9, 2023
…er (#149)

* feat: Generate SQL table schema from JSON Schemas

Squashed commits:
[a8267eb] Switch moduleResolution so @digidem/types work
[1205a2b] Fixes and add forks
[981070a] Add tests and fix accordingly
[2dac678] Add tests and fixes
[01ac065] add types for brittle
[537ff7a] Add project, preset, field schemas
[ad186ae] cleanup code and add comments
[c23cf09] fix: extract correct schema w/out schemaName param
[d8786c8] fix: docId as primary key
[36eda92] fix enum type
[f0c7eed] Remove db artifact
[89468e2] WIP: Generate SQL table schema from JSON Schemas

* skip test that is only for types

TODO: Figure out best way to test types

* new DataStore

* ts-ignore to ts-expect-error

Co-authored-by: Andrew Chou <[email protected]>

* use versionId utils from @mapeo/schema

* remove .solo

* feat: Add IndexWriter for all things indexy

Depends on:

- [ ] digidem/mapeo-sqlite-indexer#11
- [ ] digidem/mapeo-sqlite-indexer#14

Makes more sense to e2e test rather than unit test, which depends on
the new DataType class, which is next up.

* Update to published @mapeo/[email protected]

* new DataType

* stricter DataStore types

Ensures you can't create a dataType in the wrong DataStore

* pass IndexWriter to DataStore, not indexEntries fn

- More explicit relationship between indexWriter and Datastore
- Allows some type-checking to ensure  IndexWriter can process entries

* Pass storage param to data store

* chore: consistent naming

- better-sqlite3 instances = sqlite
- drizzle table definitions = table

* ensure core.key is always set

* Add drizzle migration files

* Add MapeoProject class and update e2e tests

* tests for updatedAt and createdAt

* Explicit max file descriptors

* rename test-e2e/project-crud.js

---------

Co-authored-by: Andrew Chou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants