Skip to content

Commit 34e747f

Browse files
authored
feat: add support for json and jsonb fields (#25)
1 parent a48fb1a commit 34e747f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

spec/types_from_serializers/generator_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,21 @@ def generate_serializers
115115

116116
expect(ts_type).to eq(:string)
117117
end
118+
119+
it "maps json type from SQL to object type in TypeScript" do
120+
db_type = :json
121+
122+
ts_type = TypesFromSerializers.config.sql_to_typescript_type_mapping[db_type]
123+
124+
expect(ts_type).to eq("Record<string, any>")
125+
end
126+
127+
it "maps jsonb type from SQL to object type in TypeScript" do
128+
db_type = :jsonb
129+
130+
ts_type = TypesFromSerializers.config.sql_to_typescript_type_mapping[db_type]
131+
132+
expect(ts_type).to eq("Record<string, any>")
133+
end
118134
end
119135
end

types_from_serializers/lib/types_from_serializers/generator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ def default_config(root)
392392
string: :string,
393393
text: :string,
394394
citext: :string,
395+
json: "Record<string, any>",
396+
jsonb: "Record<string, any>",
395397
}.tap do |types|
396398
types.default = :unknown
397399
end,

0 commit comments

Comments
 (0)