@@ -662,7 +662,7 @@ void main() {
662662 expect (db.select ('SELECT * FROM ps_crud' ), hasLength (1 ));
663663 });
664664
665- test ('json values are included as text' , () {
665+ test ('preserves values in text column ' , () {
666666 db
667667 ..execute ('select powersync_replace_schema(?)' , [
668668 json.encode ({
@@ -675,31 +675,44 @@ void main() {
675675 }
676676 ]
677677 })
678- ])
679- ..execute ('INSERT INTO items (id, col) VALUES (uuid(), json_object())' );
678+ ]);
679+
680+ db.execute ('INSERT INTO items (id, col) VALUES (uuid(), json_object())' );
681+ final [insert] = db.select ('SELECT data FROM ps_crud' );
682+ expect (json.decode (insert['data' ]), containsPair ('data' , {'col' : '{}' }));
683+ db.execute ('DELETE FROM ps_crud' );
680684
685+ db.execute ('UPDATE items SET col = NULL;' );
681686 final [update] = db.select ('SELECT data FROM ps_crud' );
682- expect (json.decode (update['data' ]), containsPair ('data' , {'col' : '{}' }));
687+ expect (json.decode (update['data' ]), containsPair ('data' , {'col' : null }));
688+ db.execute ('DELETE FROM ps_crud' );
683689 });
684690
685- test ('null values are included as null ' , () {
691+ test ('preserves mismatched type ' , () {
686692 db
687693 ..execute ('select powersync_replace_schema(?)' , [
688694 json.encode ({
689695 'tables' : [
690696 {
691697 'name' : 'items' ,
692698 'columns' : [
693- {'name' : 'col' , 'type' : 'text ' }
699+ {'name' : 'col' , 'type' : 'int ' }
694700 ],
695701 }
696702 ]
697703 })
698704 ])
699- ..execute ('INSERT INTO items (id, col) VALUES (uuid(), null)' );
700-
701- final [update] = db.select ('SELECT data FROM ps_crud' );
702- expect (json.decode (update['data' ]), containsPair ('data' , {}));
705+ ..execute ('insert into items (id, col) values (uuid(), json_object())' )
706+ ..execute ('insert into items (id, col) values (uuid(), null)' )
707+ ..execute ('insert into items (id, col) values (uuid(), ?)' ,
708+ ['not an integer' ]);
709+
710+ final data = db.select ('SELECT data FROM ps_crud' );
711+ expect (data.map ((row) => jsonDecode (row['data' ])), [
712+ containsPair ('data' , {'col' : '{}' }),
713+ containsPair ('data' , {}),
714+ containsPair ('data' , {'col' : 'not an integer' }),
715+ ]);
703716 });
704717 });
705718}
0 commit comments