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

Dynamic databases and store schema #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

syabiku
Copy link
Contributor

@syabiku syabiku commented Sep 26, 2021

This starts to address #9. If a manager is requested, but the database name does not exist, it will create a new dynamic database; then, store schema must be defined for it before database can receive data. DbStore class now has a property to distinguish dynamic versus static databases. Behavior of static databases and methods for operating on them should not be affected by this PR.

@syabiku syabiku marked this pull request as ready for review October 18, 2021 01:45
@nwestfall
Copy link
Owner

Great submission! I think I want to discuss the whole dynamic part a little more, but I think this has great benefit to the platform. Just want to think through some of the workflows a bit more, to support it easier.

/// <returns></returns>
public async Task<BlazorDbEvent> AddSchemaAsync(StoreSchema storeSchema)
{
if (!_dbStore.Dynamic)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just for dynamic?

@@ -32,6 +106,9 @@ window.blazorDB = {

stores[schema.name] = def;
}
if (dbStore.dynamic) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think belongs in createDb. Shouldn't it be handled in C# or in the addSchema function?

db.open().then(_ => {
db.open().then(db => {
if (dbStore.dynamic)
window.blazorDB.databases.find(d => d.name === dbStore.name).db = db;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this already happen on L113/L114?


async Task BuildNewDynamic(string dbName)
{
var newDbStore = new DbStore() { Name = dbName, StoreSchemas = new List<StoreSchema>(), Version = 0, Dynamic = true };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than open the DB here and have your logic in the javascript version to get around the Dexie bug, should we not allowed a DB to be opened if there is no schema? What's the point to open it anyway?

Thinking out loud, maybe in AddSchema we detect if any previous schemas and then open after at least 1 schema is added?

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