diff --git a/events/executed.go b/events/executed.go index 810ef13..f8d50d5 100644 --- a/events/executed.go +++ b/events/executed.go @@ -10,10 +10,10 @@ type QueryExecuted struct { Error error } -func (this *QueryExecuted) Event() string { +func (event *QueryExecuted) Event() string { return "QUERY_EXECUTED" } -func (this *QueryExecuted) Sync() bool { +func (event *QueryExecuted) Sync() bool { return true } diff --git a/go.mod b/go.mod index 3a76977..822f7ec 100644 --- a/go.mod +++ b/go.mod @@ -1,37 +1,35 @@ module github.com/goal-web/database -go 1.19 +go 1.20 require ( github.com/ClickHouse/clickhouse-go/v2 v2.0.9 github.com/go-sql-driver/mysql v1.5.0 - github.com/goal-web/application v0.1.6 - github.com/goal-web/collection v0.1.6 - github.com/goal-web/config v0.1.4 - github.com/goal-web/contracts v0.1.66 - github.com/goal-web/querybuilder v0.1.19 - github.com/goal-web/supports v0.1.32 + github.com/goal-web/application v0.2.0 + github.com/goal-web/collection v0.2.0 + github.com/goal-web/config v0.2.0 + github.com/goal-web/contracts v0.2.0 + github.com/goal-web/querybuilder v0.2.0 + github.com/goal-web/supports v0.2.0 github.com/jmoiron/sqlx v1.3.4 github.com/lib/pq v1.10.4 github.com/mattn/go-sqlite3 v1.14.10 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.1 ) require ( + github.com/BurntSushi/toml v1.2.1 // indirect github.com/apex/log v1.9.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/goal-web/container v0.1.7 // indirect + github.com/goal-web/container v0.2.0 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/kr/pretty v0.3.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/paulmach/orb v0.4.0 // indirect github.com/pierrec/lz4/v4 v4.1.14 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/qbhy/parallel v1.4.0 // indirect - github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/shopspring/decimal v1.3.1 // indirect go.opentelemetry.io/otel v1.3.0 // indirect go.opentelemetry.io/otel/trace v1.3.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d65fa20..309154d 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/ClickHouse/clickhouse-go v1.5.3/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= github.com/ClickHouse/clickhouse-go/v2 v2.0.9 h1:JKtF6JlROrcdZRMoQUTv6fW8CBSL9FiBKylXXQx5YnY= github.com/ClickHouse/clickhouse-go/v2 v2.0.9/go.mod h1:FfiBHxYkESSf1DQxROQ1kOP2XtI4Fy8XDVPasZSkI+k= @@ -24,20 +26,20 @@ github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNI github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/goal-web/application v0.1.6 h1:vrTywkConbygpQeuU8Q2B+8sLhiOUgCbeXkyuxgHPCA= -github.com/goal-web/application v0.1.6/go.mod h1:PAJkAJgmcNchOtxt9JhnDC8SenBozybHQhdbnoki4Jk= -github.com/goal-web/collection v0.1.6 h1:iSSV/EDHbMjL+o4Izvb+WnLNE2rp3HFF+q/iX7C0rQg= -github.com/goal-web/collection v0.1.6/go.mod h1:LuRggZs0gtBZpcIEVx3Kp2qkcxc/v/EcmSob8vpVe+Q= -github.com/goal-web/config v0.1.4 h1:I6EGxIysMxhwY8SPb4m51y5TvHvp1grCGk43JnhIaaQ= -github.com/goal-web/config v0.1.4/go.mod h1:qGCe2bCxt35LOjs12e8H9ZWYcaFbOet/naaoPcAFz8g= -github.com/goal-web/container v0.1.7 h1:LqAzF6vYh7sxpJgDGWzOg9t6tKbUbG3F+VBnBLl/KSo= -github.com/goal-web/container v0.1.7/go.mod h1:4NNbVCrfeFW/dM02PNm1brRF7/xAsrlkKWongztTszc= -github.com/goal-web/contracts v0.1.66 h1:X6nCPHLJXNkmfiYejd4zO78JCTGoaluBNQK/GmwUT0A= -github.com/goal-web/contracts v0.1.66/go.mod h1:lKHynU2Kgk6xyxL4afOJM4TO1kSa3RrCJ2bm5RtFMBw= -github.com/goal-web/querybuilder v0.1.19 h1:gtO3vUau3nNYe+LN0z6Im6rJLk2tjFum/qX9ZoQVIOE= -github.com/goal-web/querybuilder v0.1.19/go.mod h1:famub4R/ZBsQAx2d6Cw131pd9J+6img2eZJh5qisXak= -github.com/goal-web/supports v0.1.32 h1:gB+nbrcnTJwwSHakkJTDI15y8Vaj6sx3ToGUwo7vOnE= -github.com/goal-web/supports v0.1.32/go.mod h1:tdfY3NY4HenWU3WE7wZT0E1AljwRKWL7TgD4jL+yUoA= +github.com/goal-web/application v0.2.0 h1:MwVgbqF1rxkANIpVfHckA+vXk4e7B2a5EvQ78G5Eijg= +github.com/goal-web/application v0.2.0/go.mod h1:vZ1C82GW3ptlFiEYG1PchKu7ndbKEeMizQZqOfu/1vk= +github.com/goal-web/collection v0.2.0 h1:ERuNDxATTwqAp8Xuxm5CxoU+LEmLIxIZHQVQ7QrGmsY= +github.com/goal-web/collection v0.2.0/go.mod h1:o2/CYlKwQzUVluRbMsGh/v8nJy44bOdwpEhQDJvJM1I= +github.com/goal-web/config v0.2.0 h1:gp3pqJHoprLfu2nmgPkf/ul2M8iHpvlYkhWVL1NIyl4= +github.com/goal-web/config v0.2.0/go.mod h1:C9r93RzqRLAXoYxnxjjO9NeAgU3xN6zqDwkLO+n7y3E= +github.com/goal-web/container v0.2.0 h1:kiDhpOzXbvTvUbXCMqukXzNlHxMSW2VTMMcDisj33XA= +github.com/goal-web/container v0.2.0/go.mod h1:2ziPdY9aQjdeHYGoxK19V24du/DDUc/QxRb9bszGaFc= +github.com/goal-web/contracts v0.2.0 h1:CAk+mLD2dC//DiCV9TAUSN1zopWSrPZ8+/vCxs+cu8E= +github.com/goal-web/contracts v0.2.0/go.mod h1:33koNCIiQ7GzBmYycynenVtv5E+Jq7lWGZ8vKi5uXJQ= +github.com/goal-web/querybuilder v0.2.0 h1:k6f4AolmF0fSiN009ff9Q3Vef5wJU+C92TTZG1MWl28= +github.com/goal-web/querybuilder v0.2.0/go.mod h1:+eajJiTfWLbJRxKnfoNKwL8G0RbxwIkbh2drExih+Dc= +github.com/goal-web/supports v0.2.0 h1:I1MuDcyOSo9JJprXwvyPeV99kn/Zs/VQEM7dDsv6VyY= +github.com/goal-web/supports v0.2.0/go.mod h1:OZFq18eCd+9atA7re2gbNMZ2zWGdpuSS8WmCRsqhGm4= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -55,6 +57,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jmoiron/sqlx v1.3.4 h1:wv+0IJZfL5z0uZoUjlpKgHkgaFSYD+r9CfrXjEXsO7w= github.com/jmoiron/sqlx v1.3.4/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -89,9 +93,9 @@ github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/qbhy/parallel v1.4.0 h1:RvdjXbxIRNMG2lA6gkaEOgVhr7JbNy4BljabsD+u9JI= github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -103,11 +107,16 @@ github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUr github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= @@ -165,5 +174,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/model/model.go b/model/model.go deleted file mode 100644 index 630cefb..0000000 --- a/model/model.go +++ /dev/null @@ -1,7 +0,0 @@ -package model - -import "github.com/goal-web/contracts" - -type Model struct { - class contracts.Class -} diff --git a/schema/blueprint.go b/schema/blueprint.go deleted file mode 100644 index 3e952cc..0000000 --- a/schema/blueprint.go +++ /dev/null @@ -1,156 +0,0 @@ -package schema - -import "github.com/goal-web/supports/utils" - -type Blueprint struct { - Columns []*ColumnDefinition - Table string -} - -func (bp *Blueprint) AddColumn(typeValue, name string) *ColumnDefinition { - column := &ColumnDefinition{TypeValue: typeValue, Name: name, Table: bp.Table} - bp.Columns = append(bp.Columns, column) - return column -} - -func (bp *Blueprint) Id(name ...string) *ColumnDefinition { - return bp.BigInteger(utils.DefaultString(name, "id")).Unsigned().AutoIncrement() -} - -func (bp *Blueprint) BigInteger(name string) *ColumnDefinition { - return bp.AddColumn("bigInteger", name) -} - -func (bp *Blueprint) Integer(name string) *ColumnDefinition { - return bp.AddColumn("integer", name) -} - -func (bp *Blueprint) TinyInteger(name string) *ColumnDefinition { - return bp.AddColumn("tinyInteger", name) -} - -func (bp *Blueprint) SmallInteger(name string) *ColumnDefinition { - return bp.AddColumn("smallInteger", name) -} - -func (bp *Blueprint) MediumInteger(name string) *ColumnDefinition { - return bp.AddColumn("mediumInteger", name) -} - -func (bp *Blueprint) Float(name string, args ...int) *ColumnDefinition { - var total, places = 8, 2 - switch len(args) { - case 1: - total = args[0] - case 2: - total = args[0] - places = args[1] - } - return bp.AddColumn("float", name).Float(total, places) -} - -func (bp *Blueprint) Double(name string, args ...int) *ColumnDefinition { - var total, places = 8, 2 - switch len(args) { - case 1: - total = args[0] - case 2: - total = args[0] - places = args[1] - } - return bp.AddColumn("double", name).Float(total, places) -} - -func (bp *Blueprint) Decimal(name string, args ...int) *ColumnDefinition { - var total, places = 8, 2 - switch len(args) { - case 1: - total = args[0] - case 2: - total = args[0] - places = args[1] - } - return bp.AddColumn("decimal", name).Float(total, places) -} - -func (bp *Blueprint) Boolean(name string) *ColumnDefinition { - return bp.AddColumn("boolean", name) -} - -func (bp *Blueprint) Json(name string) *ColumnDefinition { - return bp.AddColumn("json", name) -} - -func (bp *Blueprint) Jsonb(name string) *ColumnDefinition { - return bp.AddColumn("jsonb", name) -} - -func (bp *Blueprint) Date(name string) *ColumnDefinition { - return bp.AddColumn("date", name) -} - -func (bp *Blueprint) Datetime(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("dateTime", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) DatetimeTz(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("dateTimeTz", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) Time(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("time", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) TimeTz(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("timeTz", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) Timestamp(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("timestamp", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) TimestampTz(name string, precision ...int) *ColumnDefinition { - return bp.AddColumn("timestampTz", name).Precision(utils.DefaultInt(precision)) -} - -func (bp *Blueprint) Timestamps(precision ...int) { - bp.Timestamp("created_at").Precision(utils.DefaultInt(precision)).Nullable() - bp.Timestamp("updated_at").Precision(utils.DefaultInt(precision)).Nullable() -} - -func (bp *Blueprint) TimestampsTz(precision ...int) { - bp.TimestampTz("created_at").Precision(utils.DefaultInt(precision)).Nullable() - bp.TimestampTz("updated_at").Precision(utils.DefaultInt(precision)).Nullable() -} - -func (bp *Blueprint) SoftDeletes(name ...string) *ColumnDefinition { - return bp.Timestamp(utils.DefaultString(name, "deleted_at")).Nullable() -} - -func (bp *Blueprint) SoftDeletesTz(name ...string) *ColumnDefinition { - return bp.TimestampTz(utils.DefaultString(name, "deleted_at")).Nullable() -} - -func (bp *Blueprint) Year(name string) *ColumnDefinition { - return bp.AddColumn("year", name) -} - -func (bp *Blueprint) Binary(name string) *ColumnDefinition { - return bp.AddColumn("binary", name) -} - -func (bp *Blueprint) Uuid(name string) *ColumnDefinition { - return bp.AddColumn("uuid", name) -} - -func (bp *Blueprint) IpAddress(name ...string) *ColumnDefinition { - return bp.AddColumn("ipAddress", utils.DefaultString(name, "ip_address")) -} - -func (bp *Blueprint) MacAddress(name ...string) *ColumnDefinition { - return bp.AddColumn("macAddress", utils.DefaultString(name, "mac_address")) -} - -func (bp *Blueprint) Geometry(name string) *ColumnDefinition { - return bp.AddColumn("geometry", name) -} diff --git a/schema/column.go b/schema/column.go deleted file mode 100644 index e35b522..0000000 --- a/schema/column.go +++ /dev/null @@ -1,227 +0,0 @@ -package schema - -import ( - "fmt" - "github.com/goal-web/querybuilder" -) - -type ColumnDefinition struct { - Name string - Table string - AfterColumn string - IsAutoIncrement bool - IsChange bool - CharsetValue string - CollationValue string - CommentValue string - DefaultValue any - IsFirst bool - StartValue int - IndexName string - FulltextIndexName string - SpatialIndexName string - UniqueIndexName string - IsInvisible bool - IsNullable bool - IsPersisted bool - IsPrimary bool - StoredAsExpression string - TypeValue string - IsUnsigned bool - IsUseCurrent bool - IsUseCurrentOnUpdate bool - VirtualAsExpression string - // float - TotalValue int // 总长度 - PlacesValue int // 小数点长度 - - // time - PrecisionValue int -} - -// After Place the column "after" another column (MySQL) -func (column *ColumnDefinition) After(columnName string) *ColumnDefinition { - column.AfterColumn = columnName - return column -} - -// Always Used as a modifier for generatedAs()(PostgreSQL) -func (column *ColumnDefinition) Always(value ...bool) *ColumnDefinition { - // TODO - return column -} - -// AutoIncrement Set INTEGER columns as auto-increment (primary key) -func (column *ColumnDefinition) AutoIncrement() *ColumnDefinition { - column.IsAutoIncrement = true - return column -} - -// Change the column -func (column *ColumnDefinition) Change() *ColumnDefinition { - column.IsChange = true - return column -} - -// Charset Specify a character set for the column (MySQL) -func (column *ColumnDefinition) Charset(charset string) *ColumnDefinition { - column.CharsetValue = charset - return column -} - -// Collation Specify a collation for the column (MySQL/PostgreSQL/SQL Server) -func (column *ColumnDefinition) Collation(collation string) *ColumnDefinition { - column.CollationValue = collation - return column -} - -// Comment Add a comment to the column (MySQL/PostgreSQL) -func (column *ColumnDefinition) Comment(comment string) *ColumnDefinition { - column.CommentValue = comment - return column -} - -// Default Specify a "default" value for the column -func (column *ColumnDefinition) Default(value any) *ColumnDefinition { - column.DefaultValue = value - return column -} - -// First Place the column "first" in the table (MySQL) -func (column *ColumnDefinition) First() *ColumnDefinition { - column.IsFirst = true - return column -} - -// From Set the starting value of an auto-incrementing field (MySQL / PostgreSQL) -func (column *ColumnDefinition) From(startingValue int) *ColumnDefinition { - column.StartValue = startingValue - return column -} - -// GeneratedAs Create a SQL compliant identity column (PostgreSQL) -func (column *ColumnDefinition) GeneratedAs(expression ...querybuilder.Expression) *ColumnDefinition { - // TODO - return column -} - -// Index Add an index -func (column *ColumnDefinition) Index(indexName ...string) *ColumnDefinition { - if len(indexName) > 0 { - column.IndexName = indexName[0] - } else { - column.IndexName = fmt.Sprintf("%s_%s_index", column.Table, column.Name) - } - return column -} - -// Invisible Specify that the column should be invisible to "SELECT *" (MySQL) -func (column *ColumnDefinition) Invisible() *ColumnDefinition { - column.IsInvisible = true - return column -} - -// Nullable Allow NULL values to be inserted into the column -func (column *ColumnDefinition) Nullable(value ...bool) *ColumnDefinition { - if len(value) > 0 { - column.IsNullable = value[0] - } else { - column.IsNullable = true - } - return column -} - -// Persisted Mark the computed generated column as persistent (SQL Server) -func (column *ColumnDefinition) Persisted() *ColumnDefinition { - column.IsPersisted = true - return column -} - -// Primary Add a primary index -func (column *ColumnDefinition) Primary() *ColumnDefinition { - column.IsPrimary = true - return column -} - -// Fulltext Add a fulltext index -func (column *ColumnDefinition) Fulltext(indexName ...string) *ColumnDefinition { - if len(indexName) > 0 { - column.FulltextIndexName = indexName[0] - } else { - column.FulltextIndexName = fmt.Sprintf("%s_%s_fulltext_index", column.Table, column.Name) - } - return column -} - -// SpatialIndex Add a spatial index -func (column *ColumnDefinition) SpatialIndex(indexName ...string) *ColumnDefinition { - if len(indexName) > 0 { - column.SpatialIndexName = indexName[0] - } else { - column.SpatialIndexName = fmt.Sprintf("%s_%s_spatial_index", column.Table, column.Name) - } - return column -} - -// StartingValue create a stored generated column (MySQL/PostgreSQL/SQLite) -func (column *ColumnDefinition) StartingValue(startingValue int) *ColumnDefinition { - // TODO - return column -} - -// StoredAs Create a stored generated column (MySQL/PostgreSQL/SQLite) -func (column *ColumnDefinition) StoredAs(expression string) *ColumnDefinition { - column.StoredAsExpression = expression - return column -} - -// Type Specify a type for the column -func (column *ColumnDefinition) Type(typeValue string) *ColumnDefinition { - column.TypeValue = typeValue - return column -} - -// Unique Add a unique index -func (column *ColumnDefinition) Unique(indexName ...string) *ColumnDefinition { - if len(indexName) > 0 { - column.UniqueIndexName = indexName[0] - } else { - column.UniqueIndexName = fmt.Sprintf("%s_%s_unique_index", column.Table, column.Name) - } - return column -} - -// Unsigned Set the INTEGER column as UNSIGNED (MySQL) -func (column *ColumnDefinition) Unsigned() *ColumnDefinition { - column.IsUnsigned = true - return column -} - -func (column *ColumnDefinition) Float(total, places int) *ColumnDefinition { - column.TotalValue = total - column.PlacesValue = places - return column -} - -// UseCurrent Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value -func (column *ColumnDefinition) UseCurrent() *ColumnDefinition { - column.IsUseCurrent = true - return column -} - -// UseCurrentOnUpdate Set the TIMESTAMP column to use CURRENT_TIMESTAMP when updating (MySQL) -func (column *ColumnDefinition) UseCurrentOnUpdate() *ColumnDefinition { - column.IsUseCurrentOnUpdate = true - return column -} - -// VirtualAs Create a virtual generated column (MySQL/PostgreSQL/SQLite) -func (column *ColumnDefinition) VirtualAs(expression string) *ColumnDefinition { - column.VirtualAsExpression = expression - return column -} - -func (column *ColumnDefinition) Precision(precision int) *ColumnDefinition { - column.PrecisionValue = precision - return column -} diff --git a/schema/create.go b/schema/create.go deleted file mode 100644 index 2e5e90e..0000000 --- a/schema/create.go +++ /dev/null @@ -1,6 +0,0 @@ -package schema - -func Create(table string, callback func()) error { - // TODO - return nil -}