@@ -710,5 +710,69 @@ void main() {
710710 containsPair ('data' , {'col' : 'not an integer' }),
711711 ]);
712712 });
713+
714+ group ('insert only' , () {
715+ test ('smoke test' , () {
716+ db
717+ ..execute ('select powersync_replace_schema(?)' , [
718+ json.encode ({
719+ 'tables' : [
720+ {
721+ 'name' : 'items' ,
722+ 'insert_only' : true ,
723+ 'columns' : [
724+ {'name' : 'col' , 'type' : 'int' }
725+ ],
726+ }
727+ ]
728+ })
729+ ])
730+ ..execute (
731+ 'INSERT INTO items (id, col) VALUES (uuid(), 1)' ,
732+ );
733+
734+ expect (db.select ('SELECT * FROM ps_crud' ), hasLength (1 ));
735+ // Insert-only tables don't update the $local bucket
736+ expect (db.select ('SELECT * FROM ps_buckets' ), isEmpty);
737+
738+ // Can't update or delete insert-only tables.
739+ expect (() => db.execute ('UPDATE items SET col = col + 1' ),
740+ throwsA (anything));
741+ expect (() => db.execute ('DELETE FROM items WHERE col = 1' ),
742+ throwsA (anything));
743+ });
744+
745+ test ('has no effect on local-only tables' , () {
746+ db
747+ ..execute ('select powersync_replace_schema(?)' , [
748+ json.encode ({
749+ 'tables' : [
750+ {
751+ 'name' : 'items' ,
752+ 'insert_only' : true ,
753+ 'local_only' : true ,
754+ 'columns' : [
755+ {'name' : 'col' , 'type' : 'int' }
756+ ],
757+ }
758+ ]
759+ })
760+ ]);
761+
762+ db.execute (
763+ 'INSERT INTO items (id, col) VALUES (uuid(), 1)' ,
764+ );
765+ expect (db.select ('SELECT * FROM items' ), hasLength (1 ));
766+
767+ db
768+ ..execute ('UPDATE items SET col = col + 1' )
769+ ..execute ('DELETE FROM items WHERE col = 2' );
770+ expect (db.select ('SELECT * FROM items' ), isEmpty);
771+
772+ // because this is a local-only table, no crud items should have been
773+ // created.
774+ expect (db.select ('SELECT * FROM ps_crud' ), isEmpty);
775+ });
776+ });
713777 });
714778}
0 commit comments