資料庫 大叔通過指令碼生成poco實體

2021-09-08 04:53:42 字數 1666 閱讀 3498

今天在做開發時,需要把錶對映成實體,又沒有ef這種工具,就從網上下了乙個工具,但使用時覺得太重了,所以就自己寫了乙個,基於mysql的。

功能:輸入表名,得到這個表的poco實體

select

column_type,

concat(

'public ',

case

when

left (column_type, 3) =

'int

'then

'int

'when

left (column_type, 7) =

'tinyint

'then

'byte

'when

left (column_type, 8) =

'smallint

'then

'short

'when

left (column_type, 6) =

'bigint

'then

'long

'when

left (column_type, 5) =

'float

'then

'float

'when

left (column_type, 5) =

'double

'then

'double

'when

left (column_type, 7) =

'decimal

'then

'decimal

'when

left (column_type, 4) =

'char

'then

'string

'when

left (column_type, 7) =

'varchar

'then

'string

'when

left (column_type, 4) =

'text

'then

'string

'when

left (column_type, 8) =

'datetime

'then

'datetime

'when

left (column_type, 4) =

'time

'then

'datetime

'when

left (column_type, 4) =

'date

'then

'datetime

'else

column_type

end,

'', column_name,

'')from

information_schema. columns

where

table_name ='

business_datelist

'and table_schema =

'pilipadb

';

產生的結果

我們可以直接把第二列複製到vs的實體裡就可以了,還是挺方便的!

資料庫 大叔通過指令碼生成poco實體

今天在做開發時,需要把錶對映成實體,又沒有ef這種工具,就從網上下了乙個工具,但使用時覺得太重了,所以就自己寫了乙個,基於mysql的。功能 輸入表名,得到這個表的poco實體 select column type,concat public case when left column type,3...

指令碼生成golang資料庫介面

因為 golang 提供了 database sql 的標準,所以只需要用一套指令碼就可以應用於不用的資料庫 原始碼位置 其他引數都好理解,其中 dbtype 就是 database sql 中的資料庫型別 如果是 mysql 資料庫,dbtype 填寫 mysql 如果是 sqlite 資料庫,d...

Poco資料庫操作

1.poco進行資料庫操作的步驟一般是 a.建立會話 session b.從db中讀寫資料 into,use c.使用statements d.使用容器 collection 資料,集合.e.使用limit限定 f.如何使用複雜的資料型別 如何將乙個c 物件對映到資料庫的表 下面是乙個簡單的運算元據...