@@ -123,45 +123,6 @@ func (e *MinimalTransitEncoder) EncodeMap(data map[string]interface{}) string {
123123 return `["^ ",` + strings .Join (pairs , "," ) + `]`
124124}
125125
126- // DecodeTransitLine decodes a transit-JSON line to a map (simplified)
127- func (e * MinimalTransitEncoder ) DecodeTransitLine (line string ) (map [string ]interface {}, error ) {
128- var data []interface {}
129- if err := json .Unmarshal ([]byte (line ), & data ); err != nil {
130- return nil , err
131- }
132-
133- if len (data ) == 0 || data [0 ] != "^ " {
134- return nil , fmt .Errorf ("not a transit map" )
135- }
136-
137- result := make (map [string ]interface {})
138- for i := 1 ; i < len (data ); i += 2 {
139- if i + 1 >= len (data ) {
140- break
141- }
142-
143- key , ok := data [i ].(string )
144- if ! ok {
145- continue
146- }
147-
148- // Remove ~: prefix
149- if strings .HasPrefix (key , "~:" ) {
150- key = key [2 :]
151- }
152-
153- value := data [i + 1 ]
154- // Handle ~t dates
155- if str , ok := value .(string ); ok && strings .HasPrefix (str , "~t" ) {
156- value = str [2 :]
157- }
158-
159- result [key ] = value
160- }
161-
162- return result , nil
163- }
164-
165126func TestSimpleRecordsInsert (t * testing.T ) {
166127 conn := getConnTransit (t )
167128 defer conn .Close (context .Background ())
@@ -429,94 +390,6 @@ func TestTransitJSONParsing(t *testing.T) {
429390 t .Logf ("✅ Transit-JSON OID approach working! Inserted and queried %d records with OID 16384" , count )
430391}
431392
432- /*
433- func TestTransitJSONParsingOriginal(t *testing.T) {
434- // Original test that unmarshalls the transit data:
435- conn := getConnTransit(t)
436- defer conn.Close(context.Background())
437-
438- table := getCleanTable()
439-
440- // Load sample-users-transit.json
441- file, err := os.Open("../test-data/sample-users-transit.json")
442- if err != nil {
443- t.Fatalf("Failed to open transit file: %v", err)
444- }
445- defer file.Close()
446-
447- scanner := bufio.NewScanner(file)
448- encoder := &MinimalTransitEncoder{}
449-
450- count := 0
451- for scanner.Scan() {
452- line := strings.TrimSpace(scanner.Text())
453- if line == "" {
454- continue
455- }
456-
457- // Decode transit-JSON
458- userData, err := encoder.DecodeTransitLine(line)
459- if err != nil {
460- t.Fatalf("Failed to decode transit line: %v", err)
461- }
462-
463- // Extract values with type assertions
464- id, _ := userData["_id"].(string)
465- name, _ := userData["name"].(string)
466- age := int(userData["age"].(float64))
467- active, _ := userData["active"].(bool)
468-
469- // Insert using RECORDS curly brace syntax
470- _, err = conn.Exec(context.Background(),
471- fmt.Sprintf(`INSERT INTO %s RECORDS {_id: '%s', name: '%s', age: %d, active: %v}`,
472- table, id, name, age, active))
473- if err != nil {
474- t.Fatalf("Insert failed for user %s: %v", id, err)
475- }
476- count++
477- }
478-
479- if err := scanner.Err(); err != nil {
480- t.Fatalf("Scanner error: %v", err)
481- }
482-
483- if count != 3 {
484- t.Errorf("Expected to parse 3 users, got %d", count)
485- }
486-
487- // Query back and verify
488- rows, err := conn.Query(context.Background(),
489- fmt.Sprintf("SELECT _id, name, age, active FROM %s ORDER BY _id", table))
490- if err != nil {
491- t.Fatalf("Query failed: %v", err)
492- }
493- defer rows.Close()
494-
495- verifyCount := 0
496- for rows.Next() {
497- var id, name string
498- var age int
499- var active bool
500- if err := rows.Scan(&id, &name, &age, &active); err != nil {
501- t.Fatalf("Scan failed: %v", err)
502- }
503- verifyCount++
504-
505- // Check first user
506- if verifyCount == 1 {
507- if id != "alice" || name != "Alice Smith" || age != 30 || !active {
508- t.Errorf("First user: got (%s, %s, %d, %v), expected (alice, Alice Smith, 30, true)",
509- id, name, age, active)
510- }
511- }
512- }
513-
514- if verifyCount != 3 {
515- t.Errorf("Expected 3 users from query, got %d", verifyCount)
516- }
517- }
518- */
519-
520393func TestTransitJSONWithDate (t * testing.T ) {
521394 conn := getConnTransit (t )
522395 defer conn .Close (context .Background ())
0 commit comments