lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Javier,

> if you submit a patch, i can review/try it.

I've completed the initial set of changes I was targeting. You can see
the diff here: https://github.com/jart/cosmopolitan/compare/master...pkulchenko:cosmopolitan:redbean-sqlite-session.
It's a part of the cosmopolitan project (as I'm testing it as part of
the redbean server configuration), but the changes to lsqlite3.c are
separate and independent from everything else.

Here is the Lua script using these changes:

local sqlite3 = require "lsqlite3"
local db = sqlite3.open_memory()
local ses = db:create_session()

print("create", db:exec("create table foo(k primary key, a, b, c)"))
print("insert", db:exec("insert into foo(k, a, b, c) values (1, 'v1',
'v1', 'v1')"))
local function showdata(db)
  for r in db:nrows("select * from foo") do print("select: ", r.k,
r.a, r.b, r.c) end
end
ses:attach()
print("update/1", db:exec("update foo set a = 'v2', b = 'v2' where k = 1"))
showdata(db)
local cs2 = ses:changeset()

print("update/2", db:exec("update foo set a = 'v3', b = 'v1' where k = 1"))
showdata(db)
local cs3 = ses:changeset()

print("apply1/abort", db:apply_changeset(cs2,
  function(...) print("filter", ...) return 1 end,
  function(...) print("conflict", ...) return sqlite3.CHANGESET_ABORT end))
showdata(db)

local cs4 = db:concat_changeset{db:invert_changeset(cs3), cs2, cs3}
print("apply2/no-conflict", db:apply_changeset(cs4,
  function(...) print("filter", ...) return 1 end,
  function(...) print("conflict", ...) return sqlite3.CHANGESET_REPLACE end))
showdata(db)

I've implemented most of the session/changeset/rebaser functions and
have tested them on my simple application. I tried to follow the
existing style in lsqlite3, but would appreciate a quick review to
make sure everything looks good with the changes.

I still plan to implement diff/patchset functions and add a way to
iterate over a changeset.

Paul.

On Fri, Sep 23, 2022 at 11:54 AM Javier Guerra Giraldez
<javier@guerrag.com> wrote:
>
> On Fri, 23 Sept 2022 at 13:10, Paul K <paul@zerobrane.com> wrote:
> > Before I start working on it, has anyone done any work on them already
> > that can be shared? Thank you.
>
> if you submit a patch, i can review/try it.
>
>
>
> --
> Javier