crudboy 0.1.7 → 0.2.1

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: 866c875982539e7b0bbac41b5032e96fc30652b1a66ea47b5edabaa8c8af36e7
4
- data.tar.gz: 3c022bb9a5484b178199aad45c529848e5b7f474b8cb1ee2fa6be7b673e07a71
3
+ metadata.gz: 4ac7a52e0f04007518e23a0d64c1cf670666876e64452477dd8060f324739354
4
+ data.tar.gz: 550b5ebd601d155da07b05a47a9944ce0c13f52ae14f23c3ebd4037935c08a88
5
5
  SHA512:
6
- metadata.gz: fcffdd76c72073c1da710174f78ba648440b1aa2284ed21f28d7cac757d6a4247f89b83e8748265fc4fd9b87cf9f9d5fc389d2410c1ce111af862ad53a3e83ef
7
- data.tar.gz: 876bcc15bcc8eb622a95a4676434bdd568c3af45c11ee353c0cfb2ce11a80b2c85ed52e5244231e56d8f00c143e1f100207177f09daf44a311b72019f567d480
6
+ metadata.gz: df510527319a7e9a3bb466a5c124363dc9f566365c22ccc82540d40cccea61a78eef124487941815d24787919d2e56031a861c8bec40652e8cd85431260b8d55
7
+ data.tar.gz: 59f6de8732d4b8db14f40e160bffe7b30a4c97831405c9c48204741aee57c1b706088d56ba4e71c1e40546af17bd08ccd9c3d2fdd26d1db869113772ddb52f73
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crudboy (0.1.6)
4
+ crudboy (0.2.1)
5
5
  activerecord (>= 6.0.3, < 6.2.0)
6
6
  activesupport (~> 6.0.3)
7
7
  composite_primary_keys (~> 12.0.3)
@@ -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)
data/lib/crudboy/model.rb CHANGED
@@ -14,6 +14,14 @@ module Crudboy
14
14
  columns.find { |c| c.name == active_record_model.primary_key }
15
15
  end
16
16
 
17
+ def created_at_column
18
+ columns.find { |c| c.created_at_column? }
19
+ end
20
+
21
+ def updated_at_column
22
+ columns.find { |c| c.updated_at_column? }
23
+ end
24
+
17
25
  def regular_columns
18
26
  columns.reject { |c| c.name == active_record_model.primary_key }
19
27
  end
@@ -1,3 +1,3 @@
1
1
  module Crudboy
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.1"
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.7
4
+ version: 0.2.1
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-13 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