chengkun
2025-06-05 4080b5997b38ca84b3b203c7101dcadb97b76925
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
 
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2023 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
 
namespace think\db\concern;
 
/**
 * 数据字段信息.
 */
trait TableFieldInfo
{
    /**
     * 获取数据表字段信息.
     *
     * @param string $tableName 数据表名
     *
     * @return array
     */
    public function getTableFields(string $tableName = ''): array
    {
        if ('' == $tableName) {
            $tableName = $this->getTable();
        }
 
        return $this->connection->getTableFields($tableName);
    }
 
    /**
     * 获取详细字段类型信息.
     *
     * @param string $tableName 数据表名称
     *
     * @return array
     */
    public function getFields(string $tableName = ''): array
    {
        return $this->connection->getFields($tableName ?: $this->getTable());
    }
 
    /**
     * 获取字段类型信息.
     *
     * @return array
     */
    public function getFieldsType(): array
    {
        if (!empty($this->options['field_type'])) {
            return $this->options['field_type'];
        }
 
        return $this->connection->getFieldsType($this->getTable());
    }
 
    /**
     * 获取字段类型信息.
     *
     * @param string $field 字段名
     *
     * @return string|null
     */
    public function getFieldType(string $field)
    {
        $fieldType = $this->getFieldsType();
 
        return $fieldType[$field] ?? null;
    }
 
    /**
     * 获取字段类型信息.
     *
     * @return array
     */
    public function getFieldsBindType(): array
    {
        $fieldType = $this->getFieldsType();
 
        return array_map([$this->connection, 'getFieldBindType'], $fieldType);
    }
 
    /**
     * 获取字段类型信息.
     *
     * @param string $field 字段名
     *
     * @return int
     */
    public function getFieldBindType(string $field): int
    {
        $fieldType = $this->getFieldType($field);
 
        return $this->connection->getFieldBindType($fieldType ?: '');
    }
}