crudboy 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e345152548a12acb22ef528dd46c908f288733ec20c127ada4f35e8ef6591b7e
4
- data.tar.gz: 4fb8c4aad59d49896acdf20024066f7bd61115ec3d8a2ff75a7a04de16d017e8
3
+ metadata.gz: 0b195104877b7807fcc50b78b278e7faad322cc6fd649355bfb5d0ac3ca44d61
4
+ data.tar.gz: f20d2f0e5e0af9ce981ecec211bc3454c6a2df18f3c7a5b4a2f59fdeaeec1f28
5
5
  SHA512:
6
- metadata.gz: e90df33803a2d7efac0d7b2ad27dd8c0c40da90a335ad007f704d3ded20798938275b1ddfe621d1fdf4f718391db197f0ec5524a8ff3708506d55ddc9941b55f
7
- data.tar.gz: 47c355b92e41a0afc576393831bc6a8c479d96e90ccbd8003197373b183c57c509753f225330f4c79686d4959526efe48b7b7a4a49a87d986f4572ee36e177df
6
+ metadata.gz: 868fa74a46e9b0b3762ad828fe83423095d6f8c3c98a8200d9ec8e072d2f531476c049d5684f70f3ba007f4f4773fa058a13ec82635c84807c77be7c3f262ea2
7
+ data.tar.gz: a6bcdc5a50f747a384b80126d6cf8d138de87e582d847d58af35fad0a15430c90c2f7e8dd080cfdd9938bbb14bdd783cd53f374a792111c6d9a9f2b235839ddf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crudboy (0.1.5)
4
+ crudboy (0.2.0)
5
5
  activerecord (>= 6.0.3, < 6.2.0)
6
6
  activesupport (~> 6.0.3)
7
7
  composite_primary_keys (~> 12.0.3)
@@ -53,7 +53,7 @@ GEM
53
53
  yard (~> 0.9.11)
54
54
  rainbow (3.0.0)
55
55
  rake (12.3.3)
56
- sqlite3 (1.6.8-x86_64-darwin)
56
+ sqlite3 (1.7.3-arm64-darwin)
57
57
  table_print (1.5.7)
58
58
  terminal-table (1.8.0)
59
59
  unicode-display_width (~> 1.1, >= 1.1.1)
@@ -65,11 +65,11 @@ GEM
65
65
  zeitwerk (2.6.6)
66
66
 
67
67
  PLATFORMS
68
- ruby
68
+ arm64-darwin-23
69
69
 
70
70
  DEPENDENCIES
71
71
  crudboy!
72
72
  rake (~> 12.0)
73
73
 
74
74
  BUNDLED WITH
75
- 2.2.3
75
+ 2.4.1
@@ -22,8 +22,8 @@ module Crudboy
22
22
  JDBC_TYPES = {
23
23
  "varchar" => 'VARCHAR',
24
24
  "char" => 'CHAR',
25
- "text" => 'TEXT',
26
- "longtext" => 'LONGVARCHAR',
25
+ "text" => 'VARCHAR',
26
+ "longtext" => 'VARCHAR',
27
27
  "int" => 'INTEGER',
28
28
  "smallint" => 'INTEGER',
29
29
  "bigint" => 'BIGINT',
@@ -37,6 +37,24 @@ module Crudboy
37
37
  "decimal" => 'DECIMAL'
38
38
  }
39
39
 
40
+ PYTHON_TYPES = {
41
+ "varchar" => 'str',
42
+ "char" => 'str',
43
+ "text" => 'str',
44
+ "longtext" => 'str',
45
+ "int" => 'int',
46
+ "smallint" => 'int',
47
+ "bigint" => 'int',
48
+ "tinyint" => 'int',
49
+ "double" => 'float',
50
+ "date" => 'datetime',
51
+ "datetime" => 'datetime',
52
+ "timestamp" => 'datetime',
53
+ "time" => 'datetime',
54
+ "blob" => 'bytes',
55
+ "decimal" => 'decimal'
56
+ }
57
+
40
58
  attr_accessor :active_record_column, :primary
41
59
 
42
60
  def initialize(column, primary)
@@ -87,6 +105,67 @@ module Crudboy
87
105
  JDBC_TYPES[raw_type]
88
106
  end
89
107
 
108
+ def python_type
109
+ raw_type = sql_type.scan(/^\w+/).first
110
+ PYTHON_TYPES[raw_type]
111
+ end
112
+
113
+ def python_type_with_optional
114
+ raw_python_type = python_type
115
+ null ? "Optional[#{raw_python_type}]" : raw_python_type
116
+ end
117
+
118
+ def py_sqlmodel_primary_column_declaration
119
+ format('%s: %s = Field(default_factory=gen_id, primary_key=True, max_length=%s, description="%s")', name, python_type, limit, comment)
120
+ end
121
+
122
+ def py_dto_column_declaration(optional = false)
123
+ # for example: id: str = Field(description="ID")
124
+ if optional
125
+ format('%s: %s | None = Field(description="%s", default=None)', name, python_type, comment)
126
+ else
127
+ format('%s: %s = Field(description="%s")', name, python_type, comment)
128
+ end
129
+ end
130
+
131
+ def py_sqlmodel_regular_column_declaration
132
+ if created_at_column?
133
+ return py_sqlmodel_created_at_column_declaration
134
+ end
135
+
136
+ if updated_at_column?
137
+ return py_sqlmodel_updated_at_column_declaration
138
+ end
139
+
140
+ format('%s: %s = Field(default=None, max_length=%s, description="%s")', name, python_type_with_optional, limit || 'None', comment || '')
141
+ end
142
+
143
+ def py_sqlmodel_created_at_column_declaration
144
+ # create_time: Optional[datetime] = Field(
145
+ # default_factory=datetime.now,
146
+ # description="Create Time",
147
+ # sa_column_kwargs={"server_default": sa.func.now()},
148
+ # )
149
+ format('%s: %s = Field(default_factory=datetime.now, description="%s", sa_column_kwargs={"server_default": sa.func.now()})', name, python_type_with_optional, comment || '')
150
+ end
151
+
152
+ def py_sqlmodel_updated_at_column_declaration
153
+ # update_time: Optional[datetime] = Field(
154
+ # default_factory=datetime.now,
155
+ # description="Update Time",
156
+ # sa_column_kwargs={"server_default": sa.func.now()},
157
+ # )
158
+ format('%s: %s = Field(default_factory=datetime.now, description="%s", sa_column_kwargs={"server_default": sa.func.now()})', name, python_type_with_optional, comment || '')
159
+ end
160
+
161
+ def created_at_column?
162
+ sql_type =~ /datetime|time|date|timestamp/ && name =~ /gmt_created|created_at|create_time|create_date/
163
+ end
164
+
165
+ def updated_at_column?
166
+ sql_type =~ /datetime|time|date|timestamp/ && name =~ /gmt_modified|updated_at|update_time|update_date/
167
+ end
168
+
90
169
  def method_missing(method, *args, **options, &block)
91
170
  if active_record_column.respond_to?(method)
92
171
  active_record_column.send(method, *args, **options, &block)
@@ -1,3 +1,3 @@
1
1
  module Crudboy
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crudboy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-06 00:00:00.000000000 Z
11
+ date: 2025-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2