sebastienros/yessql

Index table not created? 'no such table: UserById'

Closed this issue · 2 comments

Maybe I misunderstood how to use this library, but my first attempt failed miserably.

I did this:

static async Task Main()
{
    using var store = await StoreFactory.CreateAndInitializeAsync(config =>
    {
        config.UseSqLite(@"data source=C:\tmp\test-yessql.db");
    });
    
    store.RegisterIndexes<UserIndexProvider>();

    using var session = store.CreateSession();

    var user = new User
    {
        Name = "John Doe",
        Email = "john@doe.com"
    };
    session.Save(user);
    await session.SaveChangesAsync();
}

class User
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

class UserById : MapIndex
{
    public int UserId { get; set; }
}

class UserIndexProvider : IndexProvider<User>
{
    public override void Describe(DescribeContext<User> context)
    {
        context.For<UserById>().Map(user => new UserById { UserId = user.Id });
    }
}

When I run, the call to SaveChangesAsync() fails with this error:

SQLite Error 1: 'no such table: UserById'.

Isn't the index table created automatically? If not, how am I supposed to create it?

Same for me, and nobody answered this. Pity.

The tables are not created automatically because I thought that it could just go wrong in cases where you need to have schema changes.

The approach is that there is an API to create the tables and columns you need and then can use your preferred schema migration management API.

Here is an example taken from the samples that shows how to create the tables.

https://github.com/sebastienros/yessql/blob/main/samples%2FYesSql.Samples.Hi%2FProgram.cs#L30