3232
3333PG_MODULE_MAGIC ;
3434
35- // ============================================================================
36- // Function Declarations
37- // ============================================================================
38-
39- // Extension entry points
40- void _PG_init (void );
41- void _PG_fini (void );
42-
4335// Note: PG_FUNCTION_INFO_V1 macros are declared before each function implementation below
4436// They should NOT be duplicated here to avoid redefinition errors
4537
@@ -67,7 +59,7 @@ static cloudsync_context *get_cloudsync_context(void) {
6759
6860// MARK: - Extension Entry Points -
6961
70- void _PG_init (void ) {
62+ void _PG_init (void ) {
7163 // Extension initialization
7264 // SPI will be connected per-function call
7365 elog (DEBUG1 , "CloudSync extension loading" );
@@ -103,7 +95,7 @@ void _PG_init(void) {
10395 PG_END_TRY ();
10496}
10597
106- void _PG_fini (void ) {
98+ void _PG_fini (void ) {
10799 // Extension cleanup
108100 elog (DEBUG1 , "CloudSync extension unloading" );
109101
@@ -194,7 +186,7 @@ Datum cloudsync_db_version (PG_FUNCTION_ARGS) {
194186
195187// cloudsync_db_version_next([merging_version]) - Get next database version
196188PG_FUNCTION_INFO_V1 (cloudsync_db_version_next );
197- Datum cloudsync_db_version_next (PG_FUNCTION_ARGS ) {
189+ Datum cloudsync_db_version_next (PG_FUNCTION_ARGS ) {
198190 cloudsync_context * data = get_cloudsync_context ();
199191
200192 int64_t merging_version = CLOUDSYNC_VALUE_NOTSET ;
@@ -227,7 +219,7 @@ Datum cloudsync_db_version_next(PG_FUNCTION_ARGS) {
227219
228220// Internal helper for cloudsync_init - replicates dbsync_init logic from SQLite
229221// Returns site_id as text on success, raises error on failure
230- static text * cloudsync_init_internal (cloudsync_context * data , const char * table , const char * algo , bool skip_int_pk_check ) {
222+ static text * cloudsync_init_internal (cloudsync_context * data , const char * table , const char * algo , bool skip_int_pk_check ) {
231223 text * result = NULL ;
232224
233225 // Connect SPI for database operations
@@ -336,7 +328,7 @@ Datum cloudsync_enable (PG_FUNCTION_ARGS) {
336328
337329// cloudsync_disable - Disable sync for a table
338330PG_FUNCTION_INFO_V1 (cloudsync_disable );
339- Datum cloudsync_disable (PG_FUNCTION_ARGS ) {
331+ Datum cloudsync_disable (PG_FUNCTION_ARGS ) {
340332 if (PG_ARGISNULL (0 )) {
341333 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
342334 }
@@ -348,7 +340,7 @@ Datum cloudsync_disable(PG_FUNCTION_ARGS) {
348340
349341// cloudsync_is_enabled - Check if table is sync-enabled
350342PG_FUNCTION_INFO_V1 (cloudsync_is_enabled );
351- Datum cloudsync_is_enabled (PG_FUNCTION_ARGS ) {
343+ Datum cloudsync_is_enabled (PG_FUNCTION_ARGS ) {
352344 if (PG_ARGISNULL (0 )) {
353345 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
354346 }
@@ -365,7 +357,7 @@ Datum cloudsync_is_enabled(PG_FUNCTION_ARGS) {
365357
366358// cloudsync_cleanup - Cleanup orphaned metadata for a table
367359PG_FUNCTION_INFO_V1 (pg_cloudsync_cleanup );
368- Datum pg_cloudsync_cleanup (PG_FUNCTION_ARGS ) {
360+ Datum pg_cloudsync_cleanup (PG_FUNCTION_ARGS ) {
369361 if (PG_ARGISNULL (0 )) {
370362 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
371363 }
@@ -399,7 +391,7 @@ Datum pg_cloudsync_cleanup(PG_FUNCTION_ARGS) {
399391
400392// cloudsync_terminate - Terminate CloudSync
401393PG_FUNCTION_INFO_V1 (pg_cloudsync_terminate );
402- Datum pg_cloudsync_terminate (PG_FUNCTION_ARGS ) {
394+ Datum pg_cloudsync_terminate (PG_FUNCTION_ARGS ) {
403395 UNUSED_PARAMETER (fcinfo );
404396
405397 cloudsync_context * data = get_cloudsync_context ();
@@ -427,7 +419,7 @@ Datum pg_cloudsync_terminate(PG_FUNCTION_ARGS) {
427419
428420// cloudsync_set - Set global configuration
429421PG_FUNCTION_INFO_V1 (cloudsync_set );
430- Datum cloudsync_set (PG_FUNCTION_ARGS ) {
422+ Datum cloudsync_set (PG_FUNCTION_ARGS ) {
431423 const char * key = NULL ;
432424 const char * value = NULL ;
433425
@@ -468,7 +460,7 @@ Datum cloudsync_set(PG_FUNCTION_ARGS) {
468460
469461// cloudsync_set_table - Set table-level configuration
470462PG_FUNCTION_INFO_V1 (cloudsync_set_table );
471- Datum cloudsync_set_table (PG_FUNCTION_ARGS ) {
463+ Datum cloudsync_set_table (PG_FUNCTION_ARGS ) {
472464 const char * tbl = NULL ;
473465 const char * key = NULL ;
474466 const char * value = NULL ;
@@ -506,7 +498,7 @@ Datum cloudsync_set_table(PG_FUNCTION_ARGS) {
506498
507499// cloudsync_set_column - Set column-level configuration
508500PG_FUNCTION_INFO_V1 (cloudsync_set_column );
509- Datum cloudsync_set_column (PG_FUNCTION_ARGS ) {
501+ Datum cloudsync_set_column (PG_FUNCTION_ARGS ) {
510502 const char * tbl = NULL ;
511503 const char * col = NULL ;
512504 const char * key = NULL ;
@@ -552,7 +544,7 @@ Datum cloudsync_set_column(PG_FUNCTION_ARGS) {
552544
553545// cloudsync_begin_alter - Begin schema alteration
554546PG_FUNCTION_INFO_V1 (pg_cloudsync_begin_alter );
555- Datum pg_cloudsync_begin_alter (PG_FUNCTION_ARGS ) {
547+ Datum pg_cloudsync_begin_alter (PG_FUNCTION_ARGS ) {
556548 if (PG_ARGISNULL (0 )) {
557549 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
558550 }
@@ -588,7 +580,7 @@ Datum pg_cloudsync_begin_alter(PG_FUNCTION_ARGS) {
588580
589581// cloudsync_commit_alter - Commit schema alteration
590582PG_FUNCTION_INFO_V1 (pg_cloudsync_commit_alter );
591- Datum pg_cloudsync_commit_alter (PG_FUNCTION_ARGS ) {
583+ Datum pg_cloudsync_commit_alter (PG_FUNCTION_ARGS ) {
592584 if (PG_ARGISNULL (0 )) {
593585 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
594586 }
@@ -624,7 +616,7 @@ Datum pg_cloudsync_commit_alter(PG_FUNCTION_ARGS) {
624616
625617// Aggregate function: cloudsync_payload_encode transition function
626618PG_FUNCTION_INFO_V1 (cloudsync_payload_encode_transfn );
627- Datum cloudsync_payload_encode_transfn (PG_FUNCTION_ARGS ) {
619+ Datum cloudsync_payload_encode_transfn (PG_FUNCTION_ARGS ) {
628620 MemoryContext aggContext ;
629621 cloudsync_payload_context * payload = NULL ;
630622
@@ -665,7 +657,7 @@ Datum cloudsync_payload_encode_transfn(PG_FUNCTION_ARGS) {
665657
666658// Aggregate function: cloudsync_payload_encode finalize function
667659PG_FUNCTION_INFO_V1 (cloudsync_payload_encode_finalfn );
668- Datum cloudsync_payload_encode_finalfn (PG_FUNCTION_ARGS ) {
660+ Datum cloudsync_payload_encode_finalfn (PG_FUNCTION_ARGS ) {
669661 if (PG_ARGISNULL (0 )) {
670662 PG_RETURN_NULL ();
671663 }
@@ -696,7 +688,7 @@ Datum cloudsync_payload_encode_finalfn(PG_FUNCTION_ARGS) {
696688
697689// Payload decode - Apply changes from payload
698690PG_FUNCTION_INFO_V1 (cloudsync_payload_decode );
699- Datum cloudsync_payload_decode (PG_FUNCTION_ARGS ) {
691+ Datum cloudsync_payload_decode (PG_FUNCTION_ARGS ) {
700692 if (PG_ARGISNULL (0 )) {
701693 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("payload cannot be NULL" )));
702694 }
@@ -741,15 +733,15 @@ Datum cloudsync_payload_decode(PG_FUNCTION_ARGS) {
741733
742734// Alias for payload_decode
743735PG_FUNCTION_INFO_V1 (pg_cloudsync_payload_apply );
744- Datum pg_cloudsync_payload_apply (PG_FUNCTION_ARGS ) {
736+ Datum pg_cloudsync_payload_apply (PG_FUNCTION_ARGS ) {
745737 return cloudsync_payload_decode (fcinfo );
746738}
747739
748740// MARK: - Private/Internal Functions -
749741
750742// cloudsync_is_sync - Check if table has sync metadata
751743PG_FUNCTION_INFO_V1 (cloudsync_is_sync );
752- Datum cloudsync_is_sync (PG_FUNCTION_ARGS ) {
744+ Datum cloudsync_is_sync (PG_FUNCTION_ARGS ) {
753745 cloudsync_context * data = get_cloudsync_context ();
754746
755747 if (cloudsync_insync (data )) {
@@ -769,7 +761,7 @@ Datum cloudsync_is_sync(PG_FUNCTION_ARGS) {
769761
770762// cloudsync_seq - Get sequence number
771763PG_FUNCTION_INFO_V1 (cloudsync_seq );
772- Datum cloudsync_seq (PG_FUNCTION_ARGS ) {
764+ Datum cloudsync_seq (PG_FUNCTION_ARGS ) {
773765 UNUSED_PARAMETER (fcinfo );
774766
775767 cloudsync_context * data = get_cloudsync_context ();
@@ -780,7 +772,7 @@ Datum cloudsync_seq(PG_FUNCTION_ARGS) {
780772
781773// cloudsync_pk_encode - Encode primary key from variadic arguments
782774PG_FUNCTION_INFO_V1 (cloudsync_pk_encode );
783- Datum cloudsync_pk_encode (PG_FUNCTION_ARGS ) {
775+ Datum cloudsync_pk_encode (PG_FUNCTION_ARGS ) {
784776 int argc = 0 ;
785777 pgvalue_t * * argv = NULL ;
786778
@@ -809,7 +801,7 @@ Datum cloudsync_pk_encode(PG_FUNCTION_ARGS) {
809801
810802// cloudsync_pk_decode - Decode primary key component at given index
811803PG_FUNCTION_INFO_V1 (cloudsync_pk_decode );
812- Datum cloudsync_pk_decode (PG_FUNCTION_ARGS ) {
804+ Datum cloudsync_pk_decode (PG_FUNCTION_ARGS ) {
813805 // TODO: Implement pk_decode with callback pattern
814806 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ), errmsg ("cloudsync_pk_decode not yet implemented - requires callback implementation" )));
815807 PG_RETURN_NULL ();
@@ -818,7 +810,7 @@ Datum cloudsync_pk_decode(PG_FUNCTION_ARGS) {
818810// cloudsync_insert - Internal insert handler
819811// Signature: cloudsync_insert(table_name text, VARIADIC pk_values anyarray)
820812PG_FUNCTION_INFO_V1 (cloudsync_insert );
821- Datum cloudsync_insert (PG_FUNCTION_ARGS ) {
813+ Datum cloudsync_insert (PG_FUNCTION_ARGS ) {
822814 if (PG_ARGISNULL (0 )) {
823815 ereport (ERROR , (errcode (ERRCODE_INVALID_PARAMETER_VALUE ), errmsg ("table_name cannot be NULL" )));
824816 }
@@ -934,29 +926,28 @@ Datum cloudsync_insert(PG_FUNCTION_ARGS) {
934926
935927// Aggregate function: cloudsync_update (not implemented - complex)
936928PG_FUNCTION_INFO_V1 (cloudsync_update );
937- Datum cloudsync_update (PG_FUNCTION_ARGS ) {
929+ Datum cloudsync_update (PG_FUNCTION_ARGS ) {
938930 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ), errmsg ("cloudsync_update not yet implemented - aggregate function" )));
939931 PG_RETURN_NULL ();
940932}
941933
942934PG_FUNCTION_INFO_V1 (cloudsync_update_transfn );
943- Datum cloudsync_update_transfn (PG_FUNCTION_ARGS ) {
935+ Datum cloudsync_update_transfn (PG_FUNCTION_ARGS ) {
944936 // TODO: Implement update aggregate transition function
945937 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ), errmsg ("cloudsync_update_transfn not yet implemented" )));
946938 PG_RETURN_NULL ();
947939}
948940
949941PG_FUNCTION_INFO_V1 (cloudsync_update_finalfn );
950- Datum cloudsync_update_finalfn (PG_FUNCTION_ARGS ) {
942+ Datum cloudsync_update_finalfn (PG_FUNCTION_ARGS ) {
951943 // TODO: Implement update aggregate finalize function
952944 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ), errmsg ("cloudsync_update_finalfn not yet implemented" )));
953945 PG_RETURN_NULL ();
954946}
955947
956948// Placeholder - not implemented yet
957949PG_FUNCTION_INFO_V1 (cloudsync_payload_encode );
958- Datum
959- cloudsync_payload_encode (PG_FUNCTION_ARGS ) {
950+ Datum cloudsync_payload_encode (PG_FUNCTION_ARGS ) {
960951 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ), errmsg ("cloudsync_payload_encode should not be called directly - use aggregate version" )));
961952 PG_RETURN_NULL ();
962953}
0 commit comments