isar / isar

Extremely fast, easy to use, and fully async NoSQL database for Flutter
https://isar.dev
Apache License 2.0
3.58k stars 339 forks source link

Create TODO.md #4

Closed AKushWarrior closed 4 years ago

AKushWarrior commented 4 years ago

If you want to post a TODO.md, I'd be happy to put some time into this and the other Isar libraries.

I presume that Isar is meant to be "Hive 2.0", essentially Dart bindings to lmdb?

simc commented 4 years ago

Hey, Thanks for the offer. I'll add a todo asap.

Yes, Isar is essentially the successor of Hive but it is a little bit more than bindings for lmdb: Isar will support:

All the above also needs to be implemented with IndexedDb on the web side.

AKushWarrior commented 4 years ago

Ah, so it's a cross-platform interface to embedded databases with some advanced features wrapped in.

That makes sense to me. On the Dart side, will it use conditional imports?

simc commented 4 years ago

Ah, so it's a cross-platform interface to embedded databases with some advanced features wrapped in.

Exactly

On the Dart side, will it use conditional imports?

Yes. Initially, I wanted to write the web backend in Dart but I decided to use TypeScript instead. The Dart code will glue everything together.

AKushWarrior commented 4 years ago

@leisim why TypeScript instead of JS? Obviously static typing is nice, but does TS play nicely with https://pub.dev/packages/js?

AKushWarrior commented 4 years ago

Also, it might be worth looking into something like https://dexie.org/. As far as I can tell, it has complete support for the first 2 of your features. As for the last 3:

simc commented 4 years ago

Also, it might be worth looking into something like https://dexie.org/.

Dexie is an amazing library. In fact, it inspired some of the architectural decisions I made with Isar. For example the "WhereClause" is a great way of letting the user decide which index to use. I still think Isar would benefit from a custom implementation because it is important to make the web & native experience as similar as possible for the user.

I'm pretty sure IndexedDB has architectural constraints which disallow multi-threading

Sorry I have not been clear: Multi-threading is only planned for the native side.

Not quite sure what you mean by auto-migration

When the schema changes (properties are added or removed), the database automatically adjusts indexes and everything else without any actions from the user. This also works with IndexedDB

I assume you mean foreign key-primary key relationships

Yes. While it would be quite easy to implement such a feature for isar-core, it is almost impossible to do it in IndexedDB with decent performance. While there exist a few JavaScript libraries which support some kind of relationships, they suffer from performance issues because of the limitations of IndexedDB. My goal is that the developer never needs to think whether the app will run on mobile, desktop, or web and have 100% feature parity. So for now I decided against relationships and backlinks but if many mobile developers request this feature, we might add it in the future.

simc commented 4 years ago

but does TS play nicely with https://pub.dev/packages/js?

It does. TypeScript generates JS that looks like manually written code.

simc commented 4 years ago

I created the todo off the top of my head. I'll extend it over time.

AKushWarrior commented 4 years ago

but does TS play nicely with https://pub.dev/packages/js?

It does. TypeScript generates JS that looks like manually written code.

Cool. I've written a lot of JS, but I've only really used TS in some simple Angular webapps. I'll take your word that it works.

AKushWarrior commented 4 years ago

I created the todo off the top of my head. I'll extend it over time.

Cool. I'll take a look to see what (if anything) I can do.

simc commented 4 years ago

I've written a lot of JS

Amazing, I'm not very experienced with either JS or TypeScript so I can definitely use your help.

I'll take a look to see what (if anything) I can do.

Sorry, the code is still changing rapidly and without comments. I'll work on that :+1: I hope it's not to bad and you can navigate it...

AKushWarrior commented 4 years ago

@leisim

Maybe I should start scaffolding out TypeScript to match the Rust layer?

The reason that using dexie would be nice is because the code is already available, minified, and low maintenance. That ways we can focus on native/Dart and leave JS/TS to a dedicated dev team; it's especially true given how much crossover the wanted features list has.

On the other hand, it's just another layer where things can go wrong which we can't fix. If I was this library's architect, I think I would use Dexie for now, and then migrate later if necessary.

I'm not telling you how to run your project; if you want me to write the TS wrapper from scratch, just say the word. I just don't know if it's the most efficient usage of time considering the end goal.

AKushWarrior commented 4 years ago

@leisim I probably need a decision one way or another to start on this...

simc commented 4 years ago

@AKushWarrior sorry for the delay. The reason is a problem / possible feature I was thinking about: isar/isar#2

It needs to be solved before we can make further architecture decisions.

AKushWarrior commented 4 years ago

That's right. I'll think about that one then :).

frank06 commented 4 years ago

Happy to see you @leisim in open action again! 🎉

So for now I decided against relationships and backlinks but if many mobile developers request this feature, we might add it in the future.

If this is of any help, I see how you could focus on core features (like #2 - fantastic!) and let third party libraries implement higher level features?

Fwiw, I implemented relationships in Flutter Data using a global bi-directed graph notifier. It works with Hive as local storage, but without using Hive built-in relationships.

I'm really looking forward to having Isar as default backend.

AKushWarrior commented 4 years ago

If this is of any help, I see how you could focus on core features (like #2 - fantastic!) and let third party libraries implement higher level features?

Fwiw, I implemented relationships in Flutter Data using a global bi-directed graph notifier. It works with Hive as local storage, but without using Hive built-in relationships.

The problem is that this is still inefficient on web because IndexedDB has NO parallelization whatsoever. Thus, providing relationships would only be helpful on native, which goes against the stated purpose of cross platform feature parity.

On the other hand, I fully agree that some features (ex. foreign database integration drivers) should be abstracted into other libraries.

frank06 commented 4 years ago

Interesting, I never worked with IndexedDB. So if I had a to-many relationship modeled using a foreign key, issuing a query with a where clause on that PK is inefficient?

AKushWarrior commented 4 years ago

Interesting, I never worked with IndexedDB. So if I had a to-many relationship modeled using a foreign key, issuing a query with a where clause on that PK is inefficient?

I had a diagram somewhere I sketched out, of sample relations and how internal architecture affects them. Let me see if I can dig it up.

AKushWarrior commented 4 years ago

Okay I found the diagrams, but they're more or less incomprehensible. Some notes I pulled off them are below. For the purposes of this, assume that the user starts with a predefined db which is "foreign" and "HasMany" of something. The user will now input something into a table, in which objects "BelongsTo" the foreign table.

So a syntactical abstraction is possible, but there isn't really a sane way to implement "real" relationships.

AKushWarrior commented 4 years ago

@frank06 maybe we should relocate this discussion to #6 :)

The todo.md is done, so I'm closing this.