├── docs ├── api │ ├── other.md │ ├── _category_.json │ ├── table.md │ ├── transaction.md │ ├── lock.md │ ├── delete.md │ ├── update.md │ ├── insert.md │ ├── select.md │ └── operator.md ├── plugins │ ├── casbin.md │ ├── _category_.json │ └── opentracing.md ├── advanced-api │ ├── _category_.json │ ├── json.md │ ├── subquery.md │ └── spatial.md ├── started │ ├── _category_.json │ └── model.md ├── performance │ ├── _category_.json │ ├── index.md │ └── generated_column.md ├── migrationv1.md ├── intro.md └── changelog.md ├── static ├── .nojekyll └── img │ ├── favicon.ico │ ├── docusaurus.png │ ├── logo.svg │ └── schema_structure.svg ├── README.md ├── versions.json ├── .vscode └── settings.json ├── versioned_docs └── version-1.9 │ ├── api │ ├── _category_.json │ ├── transaction.md │ ├── table.md │ ├── delete.md │ ├── update.md │ ├── insert.md │ ├── select.md │ └── operator.md │ ├── plugins │ ├── casbin.md │ ├── _category_.json │ └── opentracing.md │ ├── advanced-api │ ├── _category_.json │ ├── json.md │ ├── subquery.md │ └── spatial.md │ ├── started │ ├── _category_.json │ └── model.md │ ├── performance │ ├── _category_.json │ ├── index.md │ └── generated_column.md │ └── intro.md ├── babel.config.js ├── src ├── pages │ ├── markdown-page.md │ ├── index.module.css │ └── index.js ├── components │ └── HomepageFeatures │ │ ├── styles.module.css │ │ └── index.js └── css │ └── custom.css ├── versioned_sidebars └── version-1.9-sidebars.json ├── i18n └── zh │ └── docusaurus-plugin-content-docs │ └── current │ └── intro.md ├── .gitignore ├── .github └── dependabot.yml ├── sidebars.js ├── package.json └── docusaurus.config.js /docs/api/other.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQLike documentation 2 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | [ 2 | "1.9" 3 | ] 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } -------------------------------------------------------------------------------- /docs/api/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "API", 3 | "position": 2 4 | } 5 | -------------------------------------------------------------------------------- /docs/plugins/casbin.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # Casbin 6 | -------------------------------------------------------------------------------- /docs/plugins/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Plugins", 3 | "position": 5 4 | } 5 | -------------------------------------------------------------------------------- /docs/advanced-api/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Advanced API", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /docs/started/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Getting Started", 3 | "position": 1 4 | } 5 | -------------------------------------------------------------------------------- /docs/performance/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Performance Tuning", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/si3nloong/sqlike-doc/dev/static/img/favicon.ico -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "API", 3 | "position": 2 4 | } 5 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/plugins/casbin.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # Casbin 6 | -------------------------------------------------------------------------------- /static/img/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/si3nloong/sqlike-doc/dev/static/img/docusaurus.png -------------------------------------------------------------------------------- /versioned_docs/version-1.9/plugins/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Plugins", 3 | "position": 5 4 | } 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/advanced-api/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Advanced API", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/started/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Getting Started", 3 | "position": 1 4 | } 5 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/performance/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Performance Tuning", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /src/pages/markdown-page.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Markdown page example 3 | --- 4 | 5 | # Markdown page example 6 | 7 | You don't need React to write simple standalone pages. 8 | -------------------------------------------------------------------------------- /versioned_sidebars/version-1.9-sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "tutorialSidebar": [ 3 | { 4 | "type": "autogenerated", 5 | "dirName": "." 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /src/components/HomepageFeatures/styles.module.css: -------------------------------------------------------------------------------- 1 | .features { 2 | display: flex; 3 | align-items: center; 4 | padding: 2rem 0; 5 | width: 100%; 6 | } 7 | 8 | .featureSvg { 9 | height: 200px; 10 | width: 200px; 11 | } 12 | -------------------------------------------------------------------------------- /docs/migrationv1.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | --- 4 | 5 | # Migration from v1 to v2 6 | 7 | - Replace `types.Date` to `civil.Date`. 8 | - `sqlike.SessionContext` 9 | - Replace package name of **github.com/si3nloong/sqlike/sqlike** to **github.com/si3nloong/sqlike/v2** 10 | - Replace `DataTyper` to `` 11 | -------------------------------------------------------------------------------- /i18n/zh/docusaurus-plugin-content-docs/current/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # sqlike 6 | 7 | > Go 对象关系映射框架. 8 | 9 | ## 安装 10 | 11 | ```console 12 | go get github.com/si3nloong/sqlike 13 | ``` 14 | 15 | ## 兼容性 16 | 17 | Sqlike did support **mysql 5.7** as well. For better compatibility, we suggest you to use at least mysql 8.0. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | .yarn.lock 22 | package-lock.json 23 | *.lock 24 | -------------------------------------------------------------------------------- /docs/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # sqlike 6 | 7 | > A golang SQL ORM which anti toxic query and focus on latest features. 8 | 9 | ## Installation 10 | 11 | ```console 12 | go get github.com/si3nloong/sqlike/v2 13 | ``` 14 | 15 | ## Legacy Support 16 | 17 | Sqlike did support **mysql 5.7** as well. For better compatibility, we suggest you to use at least mysql 8.0. 18 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # sqlike 6 | 7 | > A golang SQL ORM which anti toxic query and focus on latest features. 8 | 9 | ## Installation 10 | 11 | ```console 12 | go get github.com/si3nloong/sqlike 13 | ``` 14 | 15 | ## Legacy Support 16 | 17 | Sqlike did support **mysql 5.7** as well. For better compatibility, we suggest you to use at least mysql 8.0. 18 | -------------------------------------------------------------------------------- /src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * CSS files with the .module.css suffix will be treated as CSS modules 3 | * and scoped locally. 4 | */ 5 | 6 | .heroBanner { 7 | padding: 4rem 0; 8 | text-align: center; 9 | position: relative; 10 | overflow: hidden; 11 | } 12 | 13 | @media screen and (max-width: 996px) { 14 | .heroBanner { 15 | padding: 2rem; 16 | } 17 | } 18 | 19 | .buttons { 20 | display: flex; 21 | align-items: center; 22 | justify-content: center; 23 | } 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | target-branch: "dev" 11 | schedule: 12 | interval: "daily" -------------------------------------------------------------------------------- /sidebars.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creating a sidebar enables you to: 3 | - create an ordered group of docs 4 | - render a sidebar for each doc of that group 5 | - provide next/previous navigation 6 | 7 | The sidebars can be generated from the filesystem, or explicitly defined here. 8 | 9 | Create as many sidebars as you want. 10 | */ 11 | 12 | // @ts-check 13 | 14 | /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ 15 | const sidebars = { 16 | // By default, Docusaurus generates a sidebar from the docs folder structure 17 | tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], 18 | 19 | // But you can create a sidebar manually 20 | /* 21 | tutorialSidebar: [ 22 | { 23 | type: 'category', 24 | label: 'Tutorial', 25 | items: ['hello'], 26 | }, 27 | ], 28 | */ 29 | }; 30 | 31 | module.exports = sidebars; 32 | -------------------------------------------------------------------------------- /docs/plugins/opentracing.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # OpenTracing 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/go-sql-driver/mysql" 11 | "github.com/si3nloong/sqlike/v2/plugin/opentracing" 12 | "github.com/si3nloong/sqlike/v2/sql/instrumented" 13 | 14 | "github.com/si3nloong/sqlike" 15 | ) 16 | 17 | func main() { 18 | ctx := context.Background() 19 | driver := "mysql" 20 | cfg := mysql.NewConfig() 21 | cfg.User = "root" 22 | cfg.Passwd = "abcd1234" 23 | cfg.ParseTime = true 24 | conn, err := mysql.NewConnector(cfg) 25 | if err != nil { 26 | panic(err) 27 | } 28 | 29 | itpr := opentracing.NewInterceptor( 30 | opentracing.WithDBInstance("sqlike"), 31 | opentracing.WithDBUser(cfg.User), 32 | opentracing.WithExec(true), 33 | opentracing.WithQuery(true), 34 | ) 35 | client, err := sqlike.ConnectDB( 36 | ctx, 37 | driver, 38 | instrumented.WrapConnector(conn, itpr), 39 | ) 40 | if err != nil { 41 | panic(err) 42 | } 43 | defer client.Close() 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqlike-doc", 3 | "private": true, 4 | "scripts": { 5 | "docusaurus": "docusaurus", 6 | "start": "docusaurus start", 7 | "build": "docusaurus build", 8 | "swizzle": "docusaurus swizzle", 9 | "deploy": "docusaurus deploy", 10 | "clear": "docusaurus clear", 11 | "serve": "docusaurus serve", 12 | "write-translations": "docusaurus write-translations", 13 | "write-heading-ids": "docusaurus write-heading-ids" 14 | }, 15 | "dependencies": { 16 | "@docusaurus/core": "^2.0.0-rc.1", 17 | "@docusaurus/preset-classic": "^2.0.0-rc.1", 18 | "@mdx-js/react": "^1.6.22", 19 | "clsx": "^2.0.0", 20 | "prism-react-renderer": "^1.3.5", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0" 23 | }, 24 | "devDependencies": { 25 | "@docusaurus/module-type-aliases": "^2.0.0-rc.1" 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.5%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/plugins/opentracing.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # OpenTracing 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/go-sql-driver/mysql" 11 | "github.com/si3nloong/sqlike/plugin/opentracing" 12 | "github.com/si3nloong/sqlike/sql/instrumented" 13 | 14 | "github.com/si3nloong/sqlike" 15 | ) 16 | 17 | func main() { 18 | ctx := context.Background() 19 | driver := "mysql" 20 | cfg := mysql.NewConfig() 21 | cfg.User = "root" 22 | cfg.Passwd = "abcd1234" 23 | cfg.ParseTime = true 24 | conn, err := mysql.NewConnector(cfg) 25 | if err != nil { 26 | panic(err) 27 | } 28 | 29 | itpr := opentracing.NewInterceptor( 30 | opentracing.WithDBInstance("sqlike"), 31 | opentracing.WithDBUser(cfg.User), 32 | opentracing.WithExec(true), 33 | opentracing.WithQuery(true), 34 | ) 35 | client, err := sqlike.ConnectDB( 36 | ctx, 37 | driver, 38 | instrumented.WrapConnector(conn, itpr), 39 | ) 40 | if err != nil { 41 | panic(err) 42 | } 43 | defer client.Close() 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | --- 4 | 5 | # Changelog 6 | 7 | ## v2.0.0 8 | 9 | - Refactor folders, move some resources into **internal** folder. 10 | - Rework `sqlike.SessionContext` in `RunInTransaction` API. 11 | - Rework `DataType` interface, it's now called `ColumnDataTyper` and accept different arguments. 12 | - Support multiple tag for struct reflection, right now it supports `db`, `sqlike` and `sql` tag. 13 | - Drop custom type `types.Date`, replace it with `civil.Date` instead. 14 | - Support [multi-valued indexes](). 15 | - Support **foreign key**. 16 | - Warn user when they're using **MySQL 5.7**. 17 | - Rework encoder, `driver.Valuer` not allow to pass **Spatial** nor **JSON** value, eg : **(ST_GeomFromText('POINT(1 1)'))**. 18 | - Rework Lock API, since mysql 8.0 support [skip lock](https://dev.mysql.com/blog-archive/mysql-8-0-1-using-skip-locked-and-nowait-to-handle-hot-rows/). 19 | - Support **JOIN** clause, including **LEFT JOIN**, **INNER JOIN**. 20 | - Rework `Pagination` API. 21 | - Support Generic (go v1.18). 22 | -------------------------------------------------------------------------------- /docs/performance/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Index 6 | 7 | - [Unique Indexes](./index.md#unique-indexes) 8 | - [Full-Text Indexes](./index.md#full-text-indexes) 9 | - [Spatial Indexes](./index.md#spatial-indexes) 10 | - [Multi-Valued Indexes](./index.md#multi-valued-indexes) 11 | - Function Index 12 | 13 | ## Unique Indexes 14 | 15 | ```yaml title="index.yaml" 16 | # primary key 17 | - table: User 18 | type: primary 19 | columns: 20 | - name: ID 21 | 22 | # unique index 23 | - table: User 24 | type: unique 25 | columns: 26 | - name: Email 27 | ``` 28 | 29 | ## Full-Text Indexes 30 | 31 | ```yaml title="index.yaml" 32 | # Index `Name` column with descending order 33 | - table: User 34 | type: fulltext 35 | columns: 36 | - name: Name 37 | direction: desc 38 | comment: "User's full name" 39 | ``` 40 | 41 | ## Spatial Indexes 42 | 43 | ```yaml title="index.yaml" 44 | - table: User 45 | type: spatial 46 | columns: 47 | - name: Location 48 | ``` 49 | 50 | ## Multi-Valued Indexes 51 | 52 | ```yaml title="index.yaml" 53 | - table: User 54 | type: multi-valued 55 | columns: 56 | - name: Location 57 | ``` 58 | -------------------------------------------------------------------------------- /src/css/custom.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Any CSS included here will be global. The classic template 3 | * bundles Infima by default. Infima is a CSS framework designed to 4 | * work well for content-centric websites. 5 | */ 6 | 7 | /* You can override the default Infima variables here. */ 8 | :root { 9 | --ifm-color-primary: #2e8555; 10 | --ifm-color-primary-dark: #29784c; 11 | --ifm-color-primary-darker: #277148; 12 | --ifm-color-primary-darkest: #205d3b; 13 | --ifm-color-primary-light: #33925d; 14 | --ifm-color-primary-lighter: #359962; 15 | --ifm-color-primary-lightest: #3cad6e; 16 | --ifm-code-font-size: 95%; 17 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); 18 | } 19 | 20 | /* For readability concerns, you should choose a lighter palette in dark mode. */ 21 | [data-theme='dark'] { 22 | --ifm-color-primary: #25c2a0; 23 | --ifm-color-primary-dark: #21af90; 24 | --ifm-color-primary-darker: #1fa588; 25 | --ifm-color-primary-darkest: #1a8870; 26 | --ifm-color-primary-light: #29d5b0; 27 | --ifm-color-primary-lighter: #32d8b4; 28 | --ifm-color-primary-lightest: #4fddbf; 29 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); 30 | } 31 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/performance/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Index 6 | 7 | - [Unique Indexes](./index.md#unique-indexes) 8 | - [Full-Text Indexes](./index.md#full-text-indexes) 9 | - [Spatial Indexes](./index.md#spatial-indexes) 10 | - [Multi-Valued Indexes](./index.md#multi-valued-indexes) 11 | - Function Index 12 | 13 | ## Unique Indexes 14 | 15 | ```yaml title="index.yaml" 16 | # primary key 17 | - table: User 18 | type: primary 19 | columns: 20 | - name: ID 21 | 22 | # unique index 23 | - table: User 24 | type: unique 25 | columns: 26 | - name: Email 27 | ``` 28 | 29 | ## Full-Text Indexes 30 | 31 | ```yaml title="index.yaml" 32 | # Index `Name` column with descending order 33 | - table: User 34 | type: fulltext 35 | columns: 36 | - name: Name 37 | direction: desc 38 | comment: "User's full name" 39 | ``` 40 | 41 | ## Spatial Indexes 42 | 43 | ```yaml title="index.yaml" 44 | - table: User 45 | type: spatial 46 | columns: 47 | - name: Location 48 | ``` 49 | 50 | ## Multi-Valued Indexes 51 | 52 | ```yaml title="index.yaml" 53 | - table: User 54 | type: multi-valued 55 | columns: 56 | - name: Location 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/advanced-api/json.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # JSON 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/si3nloong/sqlike/v2/actions" 11 | "github.com/si3nloong/sqlike/v2/options" 12 | "github.com/si3nloong/sqlike/v2/sql/expr" 13 | ) 14 | 15 | /* 16 | UPDATE `sqlike`.`JSON` 17 | SET `Raw` = JSON_INSERT( 18 | JSON_REMOVE(`Raw`,"$._id"), 19 | "$.id", 20 | JSON_EXTRACT(`Raw`,"$._id") 21 | ) 22 | WHERE `ID` = 4 LIMIT 1; 23 | */ 24 | 25 | if affected, err := client.Database("sqlike"). 26 | Table("JSON"). 27 | UpdateOne( 28 | context.Background(), 29 | actions.UpdateOne(). 30 | Where( 31 | expr.Equal("ID", id), 32 | ). 33 | Set( 34 | expr.ColumnValue("Raw", 35 | expr.JSON_INSERT( 36 | expr.JSON_REMOVE(expr.Column("Raw"), "$._id"), 37 | "$.id", 38 | expr.JSON_EXTRACT(expr.Column("Raw"), "$._id"), 39 | ), 40 | ), 41 | ), 42 | options.UpdateOne().SetDebug(true), 43 | ); err != nil { 44 | panic(err) 45 | } else if affected > 0 { 46 | panic("no record affected") 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/advanced-api/json.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # JSON 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/si3nloong/sqlike/actions" 11 | "github.com/si3nloong/sqlike/options" 12 | "github.com/si3nloong/sqlike/sql/expr" 13 | ) 14 | 15 | /* 16 | UPDATE `sqlike`.`JSON` 17 | SET `Raw` = JSON_INSERT( 18 | JSON_REMOVE(`Raw`,"$._id"), 19 | "$.id", 20 | JSON_EXTRACT(`Raw`,"$._id") 21 | ) 22 | WHERE `ID` = 4 LIMIT 1; 23 | */ 24 | 25 | if affected, err := client.Database("sqlike"). 26 | Table("JSON"). 27 | UpdateOne( 28 | context.Background(), 29 | actions.UpdateOne(). 30 | Where( 31 | expr.Equal("ID", id), 32 | ). 33 | Set( 34 | expr.ColumnValue("Raw", 35 | expr.JSON_INSERT( 36 | expr.JSON_REMOVE(expr.Column("Raw"), "$._id"), 37 | "$.id", 38 | expr.JSON_EXTRACT(expr.Column("Raw"), "$._id"), 39 | ), 40 | ), 41 | ), 42 | options.UpdateOne().SetDebug(true), 43 | ); err != nil { 44 | panic(err) 45 | } else if affected > 0 { 46 | panic("no record affected") 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/transaction.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | --- 4 | 5 | # Transaction 6 | 7 | ### Handle transaction manually 8 | 9 | ```go 10 | tx, err := db.BeginTransaction(ctx) 11 | if err != nil { 12 | panic(err) 13 | } 14 | 15 | if err := db.Table("Users").FindOne( 16 | tx, 17 | actions.FindOne(). 18 | Where( 19 | expr.Equal("ID", "123"), 20 | ), 21 | ).Decode(&User{}); err != nil { 22 | // rollback transaction once it hit error 23 | tx.RollbackTransaction() 24 | panic(err) 25 | } 26 | 27 | // commit transaction 28 | tx.CommitTransaction() 29 | ``` 30 | 31 | ### Handle transaction within scope 32 | 33 | > Transaction will proceed if `error` return from scope is `nil`, else it will rollback. 34 | 35 | ```go 36 | user := User{} 37 | 38 | client.RunInTransaction( 39 | context.Background(), 40 | func(sess sqlike.SessionContext) error { 41 | if err := db.Table("Users").FindOne( 42 | sess, 43 | actions.FindOne(). 44 | Where( 45 | expr.Equal("ID", "123"), 46 | ), 47 | options.FindOne(). 48 | SetLockMode(options.LockForUpdate), 49 | ).Decode(&user); err != nil { 50 | return err 51 | } 52 | return nil 53 | }, 54 | ) 55 | ``` 56 | -------------------------------------------------------------------------------- /src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import clsx from 'clsx'; 3 | import Link from '@docusaurus/Link'; 4 | import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; 5 | import Layout from '@theme/Layout'; 6 | import HomepageFeatures from '@site/src/components/HomepageFeatures'; 7 | 8 | import styles from './index.module.css'; 9 | 10 | function HomepageHeader() { 11 | const {siteConfig} = useDocusaurusContext(); 12 | return ( 13 |
14 |
15 |

{siteConfig.title}

16 |

{siteConfig.tagline}

17 |
18 | 21 | Docusaurus Tutorial - 5min ⏱️ 22 | 23 |
24 |
25 |
26 | ); 27 | } 28 | 29 | export default function Home() { 30 | const {siteConfig} = useDocusaurusContext(); 31 | return ( 32 | 35 | 36 |
37 | 38 |
39 |
40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /docs/performance/generated_column.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # Secondary Indexes and Generated Columns 6 | 7 | InnoDB supports secondary indexes on virtual generated columns. Other index types are not supported. A secondary index defined on a virtual column is sometimes referred to as a “virtual index”. 8 | 9 | A secondary index may be created on one or more virtual columns or on a combination of virtual columns and regular columns or stored generated columns. Secondary indexes that include virtual columns may be defined as UNIQUE. 10 | 11 | - [Stored Columns](./generated_column.md#stored-columns) 12 | - [Virtual columns](./generated_column.md#virtual-columns) 13 | 14 | ## Stored Columns 15 | 16 | Use keyword `stored_column` in field tag to let **sqlike** create stored column for your table column. 17 | 18 | ```go 19 | type User struct{ 20 | Detail struct{ 21 | FirstName string `sqlike:",stored_column=Username"` 22 | LastName string 23 | } 24 | Username string `sqlike:",generated_column"` 25 | } 26 | 27 | func main() { 28 | client.Database("sqlike"). 29 | Table("users"). 30 | MustMigrate(User{}) 31 | } 32 | ``` 33 | 34 | ## Virtual Columns 35 | 36 | Use keyword `virtual_column` in field tag to create virtual column. 37 | 38 | ```go 39 | type User struct{ 40 | Detail struct{ 41 | FirstName string `sqlike:",virtual_column=Username"` 42 | LastName string 43 | } 44 | Username string `sqlike:",generated_column"` 45 | } 46 | 47 | func main() { 48 | client.Database("sqlike"). 49 | Table("users"). 50 | MustMigrate(User{}) 51 | } 52 | ``` 53 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/performance/generated_column.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # Secondary Indexes and Generated Columns 6 | 7 | InnoDB supports secondary indexes on virtual generated columns. Other index types are not supported. A secondary index defined on a virtual column is sometimes referred to as a “virtual index”. 8 | 9 | A secondary index may be created on one or more virtual columns or on a combination of virtual columns and regular columns or stored generated columns. Secondary indexes that include virtual columns may be defined as UNIQUE. 10 | 11 | - [Stored Columns](./generated_column.md#stored-columns) 12 | - [Virtual columns](./generated_column.md#virtual-columns) 13 | 14 | ## Stored Columns 15 | 16 | Use keyword `stored_column` in field tag to let **sqlike** create stored column for your table column. 17 | 18 | ```go 19 | type User struct{ 20 | Detail struct{ 21 | FirstName string `sqlike:",stored_column=Username"` 22 | LastName string 23 | } 24 | Username string `sqlike:",generated_column"` 25 | } 26 | 27 | func main() { 28 | client.Database("sqlike"). 29 | Table("users"). 30 | MustMigrate(User{}) 31 | } 32 | ``` 33 | 34 | ## Virtual Columns 35 | 36 | Use keyword `virtual_column` in field tag to create virtual column. 37 | 38 | ```go 39 | type User struct{ 40 | Detail struct{ 41 | FirstName string `sqlike:",virtual_column=Username"` 42 | LastName string 43 | } 44 | Username string `sqlike:",generated_column"` 45 | } 46 | 47 | func main() { 48 | client.Database("sqlike"). 49 | Table("users"). 50 | MustMigrate(User{}) 51 | } 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/advanced-api/subquery.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Sub-query 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/si3nloong/sqlike/v2/actions" 11 | "github.com/si3nloong/sqlike/v2/options" 12 | "github.com/si3nloong/sqlike/v2/sql/expr" 13 | ) 14 | 15 | /* 16 | SELECT * FROM `sqlike`.`NormalStruct` 17 | WHERE ( 18 | `ID` IN ( 19 | SELECT `ID` FROM `sqlike`.`NormalStruct` 20 | WHERE `Tinyint` BETWEEN 1 AND 100 21 | ORDER BY `Timestamp` DESC 22 | ) AND 23 | EXISTS (SELECT 1 FROM `sqlike`.`NormalStruct`) 24 | ) 25 | ORDER BY FIELD(`Enum`,"SUCCESS","FAILED","UNKNOWN") 26 | LIMIT 100; 27 | */ 28 | 29 | table := client.Database("sqlike").Table("Users") 30 | result, err = table.Find( 31 | context.Background(), 32 | actions.Find(). 33 | Where( 34 | expr.In("ID", actions.Find(). 35 | Select("ID"). 36 | From("sqlike", "NormalStruct"). 37 | Where( 38 | expr.Between("Tinyint", 1, 100), 39 | ). 40 | OrderBy( 41 | expr.Desc("Timestamp"), 42 | ), 43 | ), 44 | expr.Exists( 45 | actions.Find(). 46 | Select(expr.Raw("1")). 47 | From("sqlike", "NormalStruct"), 48 | ), 49 | ). 50 | OrderBy( 51 | expr.Field("Enum", []Enum{ 52 | Success, 53 | Failed, 54 | Unknown, 55 | }), 56 | ), 57 | options.Find().SetDebug(true), 58 | ) 59 | 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/advanced-api/spatial.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | # Spatial 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/paulmach/orb" 11 | "github.com/si3nloong/sqlike/v2/actions" 12 | "github.com/si3nloong/sqlike/v2/sql/expr" 13 | ) 14 | 15 | /* 16 | SELECT 17 | ST_Distance(`Point`,ST_PointFromText("POINT(20 10)")) AS `dist`, 18 | ST_Distance(ST_GeomFromText("POINT(1 3)",4326),ST_GeomFromText("POINT(4 18)",4326)),ST_AsText(`Point`) 19 | FROM `sqlike`.`Locations` 20 | WHERE ( 21 | `ID` = 1 AND 22 | ST_Equals(ST_PointFromText("POINT(20 10)"),ST_PointFromText("POINT(20 10)")) 23 | ) 24 | ORDER BY `dist` DESC LIMIT 1; 25 | */ 26 | 27 | var o struct { 28 | Dist1 float64 29 | Dist2 float64 30 | Text string 31 | } 32 | 33 | if err := client.Database("sqlike") 34 | Table("Locations"). 35 | FindOne( 36 | context.Background(), 37 | actions.FindOne(). 38 | Select( 39 | expr.As(expr.ST_Distance(expr.Column("Point"), orb.Point{20, 10}), "dist"), 40 | expr.ST_Distance( 41 | expr.ST_GeomFromText(orb.Point{1, 3}, 4326), 42 | expr.ST_GeomFromText(orb.Point{4, 18}, 4326), 43 | ), 44 | expr.ST_AsText(expr.Column("Point")), 45 | ). 46 | Where( 47 | expr.Equal("ID", 1), 48 | expr.ST_Equals(orb.Point{20, 10}, orb.Point{20, 10}), 49 | ). 50 | OrderBy( 51 | expr.Desc("dist"), 52 | ), 53 | ).Scan(&o.Dist1, &o.Dist2, &o.Text); err != nil { 54 | panic(err) 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/advanced-api/subquery.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Sub-query 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/si3nloong/sqlike/actions" 11 | "github.com/si3nloong/sqlike/options" 12 | "github.com/si3nloong/sqlike/sql/expr" 13 | ) 14 | 15 | /* 16 | SELECT * FROM `sqlike`.`NormalStruct` 17 | WHERE ( 18 | `ID` IN ( 19 | SELECT `ID` FROM `sqlike`.`NormalStruct` 20 | WHERE `Tinyint` BETWEEN 1 AND 100 21 | ORDER BY `Timestamp` DESC 22 | ) AND 23 | EXISTS (SELECT 1 FROM `sqlike`.`NormalStruct`) 24 | ) 25 | ORDER BY FIELD(`Enum`,"SUCCESS","FAILED","UNKNOWN") 26 | LIMIT 100; 27 | */ 28 | 29 | table := client.Database("sqlike").Table("Users") 30 | result, err = table.Find( 31 | context.Background(), 32 | actions.Find(). 33 | Where( 34 | expr.In("ID", actions.Find(). 35 | Select("ID"). 36 | From("sqlike", "NormalStruct"). 37 | Where( 38 | expr.Between("Tinyint", 1, 100), 39 | ). 40 | OrderBy( 41 | expr.Desc("Timestamp"), 42 | ), 43 | ), 44 | expr.Exists( 45 | actions.Find(). 46 | Select(expr.Raw("1")). 47 | From("sqlike", "NormalStruct"), 48 | ), 49 | ). 50 | OrderBy( 51 | expr.Field("Enum", []Enum{ 52 | Success, 53 | Failed, 54 | Unknown, 55 | }), 56 | ), 57 | options.Find().SetDebug(true), 58 | ) 59 | 60 | ``` 61 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/advanced-api/spatial.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | # Spatial 6 | 7 | ```go 8 | import ( 9 | "context" 10 | "github.com/paulmach/orb" 11 | "github.com/si3nloong/sqlike/actions" 12 | "github.com/si3nloong/sqlike/sql/expr" 13 | ) 14 | 15 | /* 16 | SELECT 17 | ST_Distance(`Point`,ST_PointFromText("POINT(20 10)")) AS `dist`, 18 | ST_Distance(ST_GeomFromText("POINT(1 3)",4326),ST_GeomFromText("POINT(4 18)",4326)),ST_AsText(`Point`) 19 | FROM `sqlike`.`Locations` 20 | WHERE ( 21 | `ID` = 1 AND 22 | ST_Equals(ST_PointFromText("POINT(20 10)"),ST_PointFromText("POINT(20 10)")) 23 | ) 24 | ORDER BY `dist` DESC LIMIT 1; 25 | */ 26 | 27 | var o struct { 28 | Dist1 float64 29 | Dist2 float64 30 | Text string 31 | } 32 | 33 | if err := client.Database("sqlike") 34 | Table("Locations"). 35 | FindOne( 36 | context.Background(), 37 | actions.FindOne(). 38 | Select( 39 | expr.As(expr.ST_Distance(expr.Column("Point"), orb.Point{20, 10}), "dist"), 40 | expr.ST_Distance( 41 | expr.ST_GeomFromText(orb.Point{1, 3}, 4326), 42 | expr.ST_GeomFromText(orb.Point{4, 18}, 4326), 43 | ), 44 | expr.ST_AsText(expr.Column("Point")), 45 | ). 46 | Where( 47 | expr.Equal("ID", 1), 48 | expr.ST_Equals(orb.Point{20, 10}, orb.Point{20, 10}), 49 | ). 50 | OrderBy( 51 | expr.Desc("dist"), 52 | ), 53 | ).Scan(&o.Dist1, &o.Dist2, &o.Text); err != nil { 54 | panic(err) 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/api/table.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Table and Migration 6 | 7 | ## CREATE/ALTER table 8 | 9 | ### Without dropping existing indexes and columns 10 | 11 | ```go 12 | import ( 13 | "time" 14 | "golang.org/x/text/language" 15 | "github.com/paulmach/orb" 16 | "cloud.google.com/go/civil" 17 | ) 18 | 19 | type User struct{ 20 | Name string `sqlike:",size=100"` 21 | Age uint 22 | Detail struct{ 23 | FirstName string 24 | Address string 25 | } 26 | Address string `sqlike:",longtext"` 27 | Money float64 `sqlike:",unsigned"` 28 | FavouriteFoods []string 29 | ChosenLanguage language.Tag 30 | Birthday civil.Date 31 | Geolocation orb.Point 32 | JoinAt time.Time 33 | } 34 | 35 | db := client.Database("sqlike") 36 | 37 | db.Table("Users").MustMigrate(User{}) 38 | // or 39 | db.Table("Users").Migrate(User{}) 40 | ``` 41 | 42 | ### Drop existing indexes and columns if they no longer available 43 | 44 | ```go 45 | db.Table("Users").UnsafeMigrate(User{}) 46 | ``` 47 | 48 | ## Drop table 49 | 50 | ```go 51 | client.Database("sqlike"). 52 | Table("Users"). 53 | Drop(context.Background()) 54 | ``` 55 | 56 | ## Drop table if exists 57 | 58 | ```go 59 | client.Database("sqlike"). 60 | Table("Users"). 61 | DropIfExists(context.Background()) 62 | ``` 63 | 64 | ## Rename table 65 | 66 | ```go 67 | client.Database("sqlike"). 68 | Table("Users"). 69 | Rename(context.Background(), "newUsers") 70 | ``` 71 | 72 | ## Truncate table records 73 | 74 | ```go 75 | client.Database("sqlike"). 76 | Table("Users"). 77 | Truncate(context.Background()) 78 | ``` 79 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/table.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Table and Migration 6 | 7 | ## CREATE/ALTER table 8 | 9 | ### Without dropping existing indexes and columns 10 | 11 | ```go 12 | import ( 13 | "time" 14 | "golang.org/x/text/language" 15 | "github.com/paulmach/orb" 16 | "cloud.google.com/go/civil" 17 | ) 18 | 19 | type User struct{ 20 | Name string `sqlike:",size=100"` 21 | Age uint 22 | Detail struct{ 23 | FirstName string 24 | Address string 25 | } 26 | Address string `sqlike:",longtext"` 27 | Money float64 `sqlike:",unsigned"` 28 | FavouriteFoods []string 29 | ChosenLanguage language.Tag 30 | Birthday civil.Date 31 | Geolocation orb.Point 32 | JoinAt time.Time 33 | } 34 | 35 | db := client.Database("sqlike") 36 | 37 | db.Table("Users").MustMigrate(User{}) 38 | // or 39 | db.Table("Users").Migrate(User{}) 40 | ``` 41 | 42 | ### Drop existing indexes and columns if they no longer available 43 | 44 | ```go 45 | db.Table("Users").UnsafeMigrate(User{}) 46 | ``` 47 | 48 | ## Drop table 49 | 50 | ```go 51 | client.Database("sqlike"). 52 | Table("Users"). 53 | Drop(context.Background()) 54 | ``` 55 | 56 | ## Drop table if exists 57 | 58 | ```go 59 | client.Database("sqlike"). 60 | Table("Users"). 61 | DropIfExists(context.Background()) 62 | ``` 63 | 64 | ## Rename table 65 | 66 | ```go 67 | client.Database("sqlike"). 68 | Table("Users"). 69 | Rename(context.Background(), "newUsers") 70 | ``` 71 | 72 | ## Truncate table records 73 | 74 | ```go 75 | client.Database("sqlike"). 76 | Table("Users"). 77 | Truncate(context.Background()) 78 | ``` 79 | -------------------------------------------------------------------------------- /docs/api/transaction.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | --- 4 | 5 | # Transaction 6 | 7 | ### Handle transaction manually 8 | 9 | ```go 10 | import ( 11 | "context" 12 | 13 | "github.com/si3nloong/sqlike/v2" 14 | "github.com/si3nloong/sqlike/v2/actions" 15 | "github.com/si3nloong/sqlike/v2/sql/expr" 16 | ) 17 | 18 | ctx := context.Background() 19 | tx, err := db.BeginTransaction(ctx) 20 | if err != nil { 21 | panic(err) 22 | } 23 | 24 | if err := db.Table("Users").FindOne( 25 | tx, 26 | actions.FindOne(). 27 | Where( 28 | expr.Equal("ID", "123"), 29 | ), 30 | ).Decode(&User{}); err != nil { 31 | // rollback transaction once it hit error 32 | tx.RollbackTransaction() 33 | panic(err) 34 | } 35 | 36 | // commit transaction 37 | tx.CommitTransaction() 38 | ``` 39 | 40 | ### Handle transaction within scope 41 | 42 | > Transaction will proceed if `error` return from scope is `nil`, else it will rollback. 43 | 44 | ```go 45 | import ( 46 | "context" 47 | 48 | "github.com/si3nloong/sqlike/v2" 49 | "github.com/si3nloong/sqlike/v2/actions" 50 | "github.com/si3nloong/sqlike/v2/options" 51 | "github.com/si3nloong/sqlike/v2/sql/expr" 52 | ) 53 | 54 | user := User{} 55 | 56 | client.RunInTransaction( 57 | context.Background(), 58 | func(sess sqlike.SessionContext) error { 59 | if err := db.Table("Users").FindOne( 60 | sess, 61 | actions.FindOne(). 62 | Where( 63 | expr.Equal("ID", "123"), 64 | ), 65 | options.FindOne(). 66 | SetLockMode(options.LockForUpdate), 67 | ).Decode(&user); err != nil { 68 | return err 69 | } 70 | return nil 71 | }, 72 | ) 73 | ``` 74 | -------------------------------------------------------------------------------- /docs/api/lock.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 8 3 | --- 4 | 5 | # Table Locking 6 | 7 | > A lock is a mechanism associated with a table used to restrict the unauthorized access of the data in a table. Table locking is to prevent it from unauthorized modification into the same table during a specific period. 8 | 9 | ```go 10 | import ( 11 | "context" 12 | "database/sql" 13 | "github.com/si3nloong/sqlike/v2/actions" 14 | "github.com/si3nloong/sqlike/v2/options" 15 | "github.com/si3nloong/sqlike/v2/sql/expr" 16 | ) 17 | 18 | tx, err := db.BeginTransaction(ctx) 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | if err := client.Table("Users"). 24 | FindOne( 25 | tx, 26 | actions.FindOne(). 27 | Where( 28 | expr.Equal("ID", "123"), 29 | ), 30 | options.FindOne(). 31 | SetLockMode(options.LockForUpdate), 32 | ).Decode(&user); err == sql.ErrNoRows { 33 | // record not found 34 | panic(err) 35 | } else if err != nil { 36 | panic(err) 37 | } 38 | ``` 39 | 40 | ```go 41 | import ( 42 | "context" 43 | 44 | "github.com/si3nloong/sqlike/v2/actions" 45 | "github.com/si3nloong/sqlike/v2/options" 46 | "github.com/si3nloong/sqlike/v2/sql/expr" 47 | ) 48 | 49 | client.RunInTransaction( 50 | context.Background(), 51 | func(sess sqlike.SessionContext) error { 52 | if err := db.Table("Users").FindOne( 53 | sess, 54 | actions.FindOne(). 55 | Where( 56 | expr.Equal("ID", "123"), 57 | ), 58 | options.FindOne(). 59 | SetLockMode(options.LockForUpdate), 60 | ).Decode(&user); err != nil { 61 | return err 62 | } 63 | return nil 64 | }, 65 | ) 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/api/delete.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 5 3 | --- 4 | 5 | # DELETE 6 | 7 | ## Delete Single Record 8 | 9 | ```go 10 | import ( 11 | "github.com/si3nloong/sqlike/v2/actions" 12 | "github.com/si3nloong/sqlike/v2/sql/expr" 13 | "context" 14 | 15 | _ "github.com/go-sql-driver/mysql" 16 | ) 17 | 18 | func main() { 19 | result, err := client. 20 | Database("sqlike"). 21 | Table("Users"). 22 | DeleteOne( 23 | context.Background(), 24 | actions.DeleteOne(). 25 | Where( 26 | expr.Equal("ID", 123), 27 | ), 28 | ) 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | 34 | ``` 35 | 36 | ## Delete Single Record using Primary Key 37 | 38 | ```go 39 | user := User{ 40 | Name: "Sian Loong", 41 | Age: 18, 42 | Birthday: time.Now(), 43 | } 44 | 45 | result, err := client. 46 | Database("sqlike"). 47 | Table("Users"). 48 | DestroyOne(context.Background(), &user) 49 | if err != nil { 50 | panic(err) 51 | } 52 | ``` 53 | 54 | ## Delete Multiple Record 55 | 56 | ```go 57 | import ( 58 | "github.com/si3nloong/sqlike/v2/actions" 59 | "github.com/si3nloong/sqlike/v2/sql/expr" 60 | "context" 61 | 62 | _ "github.com/go-sql-driver/mysql" 63 | ) 64 | 65 | func main() { 66 | result, err := client. 67 | Database("sqlike"). 68 | Table("Users"). 69 | Delete( 70 | context.Background(), 71 | actions.Delete(). 72 | Where( 73 | expr.Equal("Status", "frozen"), 74 | ), 75 | ) 76 | if err != nil { 77 | panic(err) 78 | } 79 | } 80 | ``` 81 | 82 | :::caution Beware 83 | 84 | `Delete` without condition (where clause) will throw error. 85 | 86 | ::: 87 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/delete.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 5 3 | --- 4 | 5 | # DELETE 6 | 7 | ## Delete Single Record 8 | 9 | ```go 10 | import ( 11 | "github.com/si3nloong/sqlike/actions" 12 | "github.com/si3nloong/sqlike/sql/expr" 13 | "context" 14 | 15 | _ "github.com/go-sql-driver/mysql" 16 | ) 17 | 18 | func main() { 19 | result, err := client. 20 | Database("sqlike"). 21 | Table("Users"). 22 | DeleteOne( 23 | context.Background(), 24 | actions.DeleteOne(). 25 | Where( 26 | expr.Equal("ID", 123), 27 | ), 28 | ) 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | 34 | ``` 35 | 36 | ## Delete Single Record using Primary Key 37 | 38 | ```go 39 | user := User{ 40 | Name: "Sian Loong", 41 | Age: 18, 42 | Birthday: time.Now(), 43 | } 44 | 45 | result, err := client. 46 | Database("sqlike"). 47 | Table("Users"). 48 | DestroyOne(context.Background(), &user) 49 | if err != nil { 50 | panic(err) 51 | } 52 | ``` 53 | 54 | ## Delete Multiple Record 55 | 56 | ```go 57 | import ( 58 | "github.com/si3nloong/sqlike/actions" 59 | "github.com/si3nloong/sqlike/sql/expr" 60 | "context" 61 | 62 | _ "github.com/go-sql-driver/mysql" 63 | ) 64 | 65 | func main() { 66 | result, err := client. 67 | Database("sqlike"). 68 | Table("Users"). 69 | Delete( 70 | context.Background(), 71 | actions.Delete(). 72 | Where( 73 | expr.Equal("Status", "frozen"), 74 | ), 75 | ) 76 | if err != nil { 77 | panic(err) 78 | } 79 | } 80 | ``` 81 | 82 | :::caution Beware 83 | 84 | `Delete` without condition (where clause) will throw error. 85 | 86 | ::: 87 | -------------------------------------------------------------------------------- /docs/api/update.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 4 3 | --- 4 | 5 | # UPDATE 6 | 7 | ## Update Single Record 8 | 9 | ```go 10 | import ( 11 | "github.com/si3nloong/sqlike/v2/actions" 12 | "github.com/si3nloong/sqlike/v2/sql/expr" 13 | "context" 14 | 15 | _ "github.com/go-sql-driver/mysql" 16 | ) 17 | 18 | func main() { 19 | result, err := client. 20 | Database("sqlike"). 21 | Table("Users"). 22 | UpdateOne( 23 | context.Background(), 24 | actions.UpdateOne(). 25 | Where( 26 | expr.Equal("ID", 123), 27 | ). 28 | Set( 29 | expr.ColumnValue("Age", 18), 30 | ), 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | } 36 | 37 | ``` 38 | 39 | ## Update Single Record with Primary Key 40 | 41 | ```go 42 | user := User{ 43 | Name: "Sian Loong", 44 | Age: 18, 45 | Birthday: time.Now(), 46 | } 47 | 48 | result, err := client. 49 | Database("sqlike"). 50 | Table("Users"). 51 | ModifyOne(context.Background(), &user) 52 | if err != nil { 53 | panic(err) 54 | } 55 | ``` 56 | 57 | ## Update Multiple Record 58 | 59 | ```go 60 | import ( 61 | "github.com/si3nloong/sqlike/v2/sqlike/actions" 62 | "github.com/si3nloong/sqlike/v2/sql/expr" 63 | "context" 64 | 65 | _ "github.com/go-sql-driver/mysql" 66 | ) 67 | 68 | func main() { 69 | result, err := client. 70 | Database("sqlike"). 71 | Table("Users"). 72 | Update( 73 | context.Background(), 74 | actions.Update(). 75 | Where( 76 | expr.Equal("Status", "frozen"), 77 | ). 78 | Set( 79 | expr.ColumnValue("Age", 18), 80 | ), 81 | ) 82 | if err != nil { 83 | panic(err) 84 | } 85 | } 86 | ``` 87 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/update.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 4 3 | --- 4 | 5 | # UPDATE 6 | 7 | ## Update Single Record 8 | 9 | ```go 10 | import ( 11 | "github.com/si3nloong/sqlike/actions" 12 | "github.com/si3nloong/sqlike/sql/expr" 13 | "context" 14 | 15 | _ "github.com/go-sql-driver/mysql" 16 | ) 17 | 18 | func main() { 19 | result, err := client. 20 | Database("sqlike"). 21 | Table("Users"). 22 | UpdateOne( 23 | context.Background(), 24 | actions.UpdateOne(). 25 | Where( 26 | expr.Equal("ID", 123), 27 | ). 28 | Set( 29 | expr.ColumnValue("Age", 18), 30 | ), 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | } 36 | 37 | ``` 38 | 39 | ## Update Single Record with Primary Key 40 | 41 | ```go 42 | user := User{ 43 | Name: "Sian Loong", 44 | Age: 18, 45 | Birthday: time.Now(), 46 | } 47 | 48 | result, err := client. 49 | Database("sqlike"). 50 | Table("Users"). 51 | ModifyOne(context.Background(), &user) 52 | if err != nil { 53 | panic(err) 54 | } 55 | ``` 56 | 57 | ## Update Multiple Record 58 | 59 | ```go 60 | import ( 61 | "github.com/si3nloong/sqlike/sqlike/actions" 62 | "github.com/si3nloong/sqlike/sql/expr" 63 | "context" 64 | 65 | _ "github.com/go-sql-driver/mysql" 66 | ) 67 | 68 | func main() { 69 | result, err := client. 70 | Database("sqlike"). 71 | Table("Users"). 72 | Update( 73 | context.Background(), 74 | actions.Update(). 75 | Where( 76 | expr.Equal("Status", "frozen"), 77 | ). 78 | Set( 79 | expr.ColumnValue("Age", 18), 80 | ), 81 | ) 82 | if err != nil { 83 | panic(err) 84 | } 85 | } 86 | ``` 87 | -------------------------------------------------------------------------------- /src/components/HomepageFeatures/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import clsx from "clsx"; 3 | import styles from "./styles.module.css"; 4 | 5 | const FeatureList = [ 6 | { 7 | title: "Easy to Use", 8 | Svg: require("@site/static/img/logo.svg").default, 9 | description: ( 10 | <> 11 | Docusaurus was designed from the ground up to be easily installed and 12 | used to get your website up and running quickly. 13 | 14 | ), 15 | }, 16 | { 17 | title: "Focus on What Matters", 18 | Svg: require("@site/static/img/logo.svg").default, 19 | description: ( 20 | <> 21 | Docusaurus lets you focus on your docs, and we'll do the chores. Go 22 | ahead and move your docs into the docs directory. 23 | 24 | ), 25 | }, 26 | { 27 | title: "Powered by React", 28 | Svg: require("@site/static/img/logo.svg").default, 29 | description: ( 30 | <> 31 | Extend or customize your website layout by reusing React. Docusaurus can 32 | be extended while reusing the same header and footer. 33 | 34 | ), 35 | }, 36 | ]; 37 | 38 | function Feature({ Svg, title, description }) { 39 | return ( 40 |
41 |
42 | 43 |
44 |
45 |

{title}

46 |

{description}

47 |
48 |
49 | ); 50 | } 51 | 52 | export default function HomepageFeatures() { 53 | return ( 54 |
55 |
56 |
57 | {FeatureList.map((props, idx) => ( 58 | 59 | ))} 60 |
61 |
62 |
63 | ); 64 | } 65 | -------------------------------------------------------------------------------- /docs/api/insert.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | # INSERT 6 | 7 | ## Insert Single Record 8 | 9 | ```go 10 | import ( 11 | "context" 12 | "time" 13 | ) 14 | 15 | user := User{ 16 | Name: "Sian Loong", 17 | Age: 18, 18 | Birthday: time.Now(), 19 | } 20 | 21 | result, err := client. 22 | Database("sqlike"). 23 | Table("Users"). 24 | InsertOne(context.Background(), &user) 25 | if err != nil { 26 | panic(err) 27 | } 28 | ``` 29 | 30 | ## Insert Multiple Record 31 | 32 | ```go 33 | import ( 34 | "context" 35 | "time" 36 | ) 37 | 38 | users := []User{ 39 | User{ 40 | ID: 1, 41 | Name: "Sian Loong", 42 | Age: 18, 43 | Birthday: time.Now(), 44 | }, 45 | User{ 46 | ID: 2, 47 | Name: "John Doe", 48 | Age: 26, 49 | Birthday: time.Now(), 50 | }, 51 | } 52 | 53 | result, err := client. 54 | Database("sqlike"). 55 | Table("Users"). 56 | Insert(context.Background(), &users) 57 | if err != nil { 58 | panic(err) 59 | } 60 | ``` 61 | 62 | ## Upsert Single Record 63 | 64 | > If record found, replace old record, else add as new record. 65 | 66 | ```go 67 | import ( 68 | "context" 69 | "time" 70 | "github.com/si3nloong/sqlike/v2/options" 71 | ) 72 | 73 | user := User{ 74 | Name: "Sian Loong", 75 | Age: 18, 76 | Birthday: time.Now(), 77 | } 78 | 79 | result, err := client. 80 | Database("sqlike"). 81 | Table("Users"). 82 | InsertOne( 83 | context.Background(), 84 | &user, 85 | options.InsertOne(). 86 | SetMode(options.InsertOnDuplicate)) 87 | ) 88 | if err != nil { 89 | panic(err) 90 | } 91 | ``` 92 | 93 | ## Insert Ignore Single Record 94 | 95 | > If record found, skip it, else add as new record. 96 | 97 | ```go 98 | import ( 99 | "context" 100 | "time" 101 | "github.com/si3nloong/sqlike/v2/options" 102 | ) 103 | 104 | user := User{ 105 | Name: "Sian Loong", 106 | Age: 18, 107 | Birthday: time.Now(), 108 | } 109 | 110 | result, err := client. 111 | Database("sqlike"). 112 | Table("Users"). 113 | InsertOne( 114 | context.Background(), 115 | &user, 116 | options.InsertOne(). 117 | SetMode(options.InsertIgnore)) 118 | ) 119 | if err != nil { 120 | panic(err) 121 | } 122 | ``` 123 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/insert.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | # INSERT 6 | 7 | ## Insert Single Record 8 | 9 | ```go 10 | import ( 11 | "context" 12 | "time" 13 | ) 14 | 15 | user := User{ 16 | Name: "Sian Loong", 17 | Age: 18, 18 | Birthday: time.Now(), 19 | } 20 | 21 | result, err := client. 22 | Database("sqlike"). 23 | Table("Users"). 24 | InsertOne(context.Background(), &user) 25 | if err != nil { 26 | panic(err) 27 | } 28 | ``` 29 | 30 | ## Insert Multiple Record 31 | 32 | ```go 33 | import ( 34 | "context" 35 | "time" 36 | ) 37 | 38 | users := []User{ 39 | User{ 40 | ID: 1, 41 | Name: "Sian Loong", 42 | Age: 18, 43 | Birthday: time.Now(), 44 | }, 45 | User{ 46 | ID: 2, 47 | Name: "John Doe", 48 | Age: 26, 49 | Birthday: time.Now(), 50 | }, 51 | } 52 | 53 | result, err := client. 54 | Database("sqlike"). 55 | Table("Users"). 56 | Insert(context.Background(), &users) 57 | if err != nil { 58 | panic(err) 59 | } 60 | ``` 61 | 62 | ## Upsert Single Record 63 | 64 | > If record found, replace old record, else add as new record. 65 | 66 | ```go 67 | import ( 68 | "context" 69 | "time" 70 | "github.com/si3nloong/sqlike/options" 71 | ) 72 | 73 | user := User{ 74 | Name: "Sian Loong", 75 | Age: 18, 76 | Birthday: time.Now(), 77 | } 78 | 79 | result, err := client. 80 | Database("sqlike"). 81 | Table("Users"). 82 | InsertOne( 83 | context.Background(), 84 | &user, 85 | options.InsertOne(). 86 | SetMode(options.InsertOnDuplicate)) 87 | ) 88 | if err != nil { 89 | panic(err) 90 | } 91 | ``` 92 | 93 | ## Insert Ignore Single Record 94 | 95 | > If record found, skip it, else add as new record. 96 | 97 | ```go 98 | import ( 99 | "context" 100 | "time" 101 | "github.com/si3nloong/sqlike/options" 102 | ) 103 | 104 | user := User{ 105 | Name: "Sian Loong", 106 | Age: 18, 107 | Birthday: time.Now(), 108 | } 109 | 110 | result, err := client. 111 | Database("sqlike"). 112 | Table("Users"). 113 | InsertOne( 114 | context.Background(), 115 | &user, 116 | options.InsertOne(). 117 | SetMode(options.InsertIgnore)) 118 | ) 119 | if err != nil { 120 | panic(err) 121 | } 122 | ``` 123 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/started/model.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Model 6 | 7 | Value after prefix of keyword `sqlike` always a column name. To define multiple tag value, you can use **comma** to separate it. 8 | 9 | | Field Tag | Value Required | Value Data Type | Description | 10 | | ------------------ | -------------- | --------------- | ------------------------------------------------------------ | 11 | | `-` | no | - | skip this field | 12 | | `size` | yes | `integer` | set column length | 13 | | `comment` | yes | `string` | set column comment | 14 | | `primary_key` | no | - | set column as primary key | 15 | | `generated_column` | no | - | column length | 16 | | `virtual_column` | no | `string` | make column as virtual column | 17 | | `stored_column` | no | `string` | make column as stored column | 18 | | `charset` | yes | `string` | set column character set | 19 | | `collate` | yes | `string` | set column collation | 20 | | `auto_increment` | no | - | set column as auto increment, mainly for primary key purpose | 21 | | `set` | yes | `[]string` | set column to **SET** data type and available values | 22 | | `enum` | yes | `[]string` | set column to **ENUM** data type and available values | 23 | | `longtext` | no | - | set column to **LONGTEXT** data type | 24 | | `unsigned` | no | - | set column to unsigned (Only applicable to number data type) | 25 | | `default` | yes | `any` | set column default value | 26 | 27 | ## Example 28 | 29 | ```go 30 | type User struct{ 31 | ID int64 `sqlike:",primary_key,auto_increment"` 32 | FullName string `sqlike:",generated_column"` 33 | Detail struct{ 34 | FirstName string `sqlike:",stored_column=FullName"` 35 | } 36 | Money float64 `sqlike:",unsigned"` 37 | Address string `sqlike:",longtext"` 38 | Email string `sqlike:",size=100"` 39 | Status string `sqlike:",enum=Frozen|IDLE"` 40 | } 41 | ``` 42 | -------------------------------------------------------------------------------- /docs/started/model.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Model 6 | 7 | SQLike accept multiple scheme key values, the available one are **db**, **sql**, or **sqlike**. 8 | 9 | 10 | 11 | The value after the scheme is always a **column name**. To define multiple modifiers, you can use **comma** to separate them. 12 | 13 | ## Column Modifiers 14 | 15 | | Field Tag | Value Required | Value Data Type | Description | 16 | | ------------------ | -------------- | --------------- | ------------------------------------------------------------ | 17 | | `-` | no | - | skip this field | 18 | | `size` | yes | `integer` | set column length | 19 | | `comment` | yes | `string` | set column comment | 20 | | `primary_key` | no | - | set column as primary key | 21 | | `foreign_key` | no | - | set column as foreign key | 22 | | `generated_column` | no | - | column length | 23 | | `virtual_column` | no | `string` | make column as virtual column | 24 | | `stored_column` | no | `string` | make column as stored column | 25 | | `charset` | yes | `string` | set column character set | 26 | | `collate` | yes | `string` | set column collation | 27 | | `auto_increment` | no | - | set column as auto increment, mainly for primary key purpose | 28 | | `set` | yes | `[]string` | set column to **SET** data type and available values | 29 | | `enum` | yes | `[]string` | set column to **ENUM** data type and available values | 30 | | `longtext` | no | - | set column to **LONGTEXT** data type | 31 | | `unsigned` | no | - | set column to unsigned (Only applicable to number data type) | 32 | | `default` | yes | `any` | set column default value | 33 | 34 | ## Example 35 | 36 | ```go 37 | type User struct{ 38 | ID int64 `sqlike:",primary_key,auto_increment"` 39 | FullName string `sqlike:",generated_column"` 40 | Detail struct{ 41 | FirstName string `sqlike:",stored_column=FullName"` 42 | } 43 | Money float64 `sqlike:",unsigned"` 44 | Address string `sqlike:",longtext"` 45 | Email string `sqlike:",size=100"` 46 | Status string `sqlike:",enum=Frozen|IDLE"` 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /docs/api/select.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # SELECT 6 | 7 | The **SELECT** statement is used to select data from a table. 8 | 9 | ## Find Single Record 10 | 11 | Select single record from a table. 12 | 13 | ```go 14 | import ( 15 | "context" 16 | "database/sql" 17 | "github.com/si3nloong/sqlike/v2/actions" 18 | "github.com/si3nloong/sqlike/v2/sql/expr" 19 | ) 20 | 21 | user := User{} 22 | 23 | if err := client.Table("Users"). 24 | FindOne( 25 | context.Background(), 26 | actions.FindOne(). 27 | Where( 28 | expr.Equal("ID", "123"), 29 | ), 30 | ).Decode(&user); err == sql.ErrNoRows { 31 | // record not found 32 | panic(err) 33 | } else if err != nil { 34 | panic(err) 35 | } 36 | ``` 37 | 38 | :::caution Beware 39 | 40 | If the record not found, it will throw `sql.ErrNoRows` error, remember to handle with care. 41 | 42 | ::: 43 | 44 | ## Select Multiple Record with `All` 45 | 46 | Select multiple record from a table and map to pointer of array of struct. 47 | 48 | ```go 49 | import ( 50 | "context" 51 | "github.com/si3nloong/sqlike/v2/sqlike/actions" 52 | "github.com/si3nloong/sqlike/v2/sql/expr" 53 | ) 54 | 55 | users := []User{} 56 | 57 | result, err := client.Table("Users"). 58 | Find( 59 | context.Background(), 60 | actions.Find(). 61 | Where( 62 | expr.In("Status", []string{"Frozen", "Active"}), 63 | ), 64 | ) 65 | if err != nil { 66 | panic(err) 67 | } 68 | 69 | if err := result.All(&users); err != nil { 70 | panic(err) 71 | } 72 | ``` 73 | 74 | :::caution Beware 75 | 76 | `Result` will close automatically once `All` is called. 77 | 78 | ::: 79 | 80 | ## Select Multiple Record with `Decode` 81 | 82 | Select multiple record from a table and manually map it to struct. 83 | 84 | ```go 85 | import ( 86 | "context" 87 | "github.com/si3nloong/sqlike/v2/sqlike/actions" 88 | "github.com/si3nloong/sqlike/v2/sql/expr" 89 | ) 90 | 91 | ctx := context.Background() 92 | users := []User{} 93 | 94 | result, err := client.Table("Users"). 95 | Find( 96 | ctx, 97 | actions.Find(). 98 | Where( 99 | expr.In("Status", []string{"Frozen", "Active"}), 100 | ), 101 | ) 102 | if err != nil { 103 | panic(err) 104 | } 105 | defer result.Close() 106 | 107 | for result.Next() { 108 | var user User 109 | if err := result.Decode(&user); err != nil { 110 | panic(err) 111 | } 112 | 113 | users = append(users, user) 114 | } 115 | ``` 116 | 117 | :::danger DON'T FORGET 118 | 119 | Remember to call `Close` once you no longer need the result, else it will lead to **memory leak**! 120 | 121 | ::: 122 | 123 | ## Pagination 124 | 125 | ### Offset pagination 126 | 127 | ### Cursor based pagination 128 | 129 | ## FAQs 130 | 131 | I see there have a lot of similar api, such as `Scan`, `Slice`, `All` and many more, what exactly is them? 132 | 133 | - Scan - To decode into slice of `interface{}` 134 | - Decode - To decode into `struct` 135 | - Slice - To decode into `[]T` 136 | - All - To decode into `[]T` 137 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/select.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # SELECT 6 | 7 | The **SELECT** statement is used to select data from a table. 8 | 9 | ## Find Single Record 10 | 11 | Select single record from a table and map to pointer of struct. 12 | 13 | ```go 14 | import ( 15 | "context" 16 | "database/sql" 17 | "github.com/si3nloong/sqlike/actions" 18 | "github.com/si3nloong/sqlike/sql/expr" 19 | ) 20 | 21 | user := User{} 22 | 23 | if err := client.Table("Users"). 24 | FindOne( 25 | context.Background(), 26 | actions.FindOne(). 27 | Where( 28 | expr.Equal("ID", "123"), 29 | ), 30 | ).Decode(&user); err == sql.ErrNoRows { 31 | // record not found 32 | panic(err) 33 | } else if err != nil { 34 | panic(err) 35 | } 36 | ``` 37 | 38 | :::caution Beware 39 | 40 | If the record not found, it will throw `sql.ErrNoRows` error, remember to handle with care. 41 | 42 | ::: 43 | 44 | ## Select Multiple Record with `All` 45 | 46 | Select multiple record from a table and map to pointer of array of struct. 47 | 48 | ```go 49 | import ( 50 | "context" 51 | "github.com/si3nloong/sqlike/sqlike/actions" 52 | "github.com/si3nloong/sqlike/sql/expr" 53 | ) 54 | 55 | users := []User{} 56 | 57 | result, err := client.Table("Users"). 58 | Find( 59 | context.Background(), 60 | actions.Find(). 61 | Where( 62 | expr.In("Status", []string{"Frozen", "Active"}), 63 | ), 64 | ) 65 | if err != nil { 66 | panic(err) 67 | } 68 | 69 | if err := result.All(&users); err != nil { 70 | panic(err) 71 | } 72 | ``` 73 | 74 | :::caution Beware 75 | 76 | `Result` will close automatically once `All` is called. 77 | 78 | ::: 79 | 80 | ## Select Multiple Record with `Decode` 81 | 82 | Select multiple record from a table and manually map it to struct. 83 | 84 | ```go 85 | import ( 86 | "context" 87 | "github.com/si3nloong/sqlike/sqlike/actions" 88 | "github.com/si3nloong/sqlike/sql/expr" 89 | ) 90 | 91 | ctx := context.Background() 92 | users := []User{} 93 | 94 | result, err := client.Table("Users"). 95 | Find( 96 | ctx, 97 | actions.Find(). 98 | Where( 99 | expr.In("Status", []string{"Frozen", "Active"}), 100 | ), 101 | ) 102 | if err != nil { 103 | panic(err) 104 | } 105 | defer result.Close() 106 | 107 | for result.Next() { 108 | var user User 109 | if err := result.Decode(&user); err != nil { 110 | panic(err) 111 | } 112 | 113 | users = append(users, user) 114 | } 115 | ``` 116 | 117 | :::danger DON'T FORGET 118 | 119 | Remember to call `Close` once you no longer need the result, else it will lead to **memory leak**! 120 | 121 | ::: 122 | 123 | ## Pagination 124 | 125 | ### Offset pagination 126 | 127 | ### Cursor based pagination 128 | 129 | ## FAQs 130 | 131 | I see there have a lot of similar api, such as `Scan`, `Slice`, `All` and many more, what exactly is them? 132 | 133 | - Scan - To decode into slice of `interface{}` 134 | - Decode - To decode into `struct` 135 | - Slice - To decode into `[]T` 136 | - All - To decode into `[]T` 137 | -------------------------------------------------------------------------------- /docs/api/operator.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | --- 4 | 5 | # Expression/Operator 6 | 7 | ```go 8 | import ( 9 | "github.com/si3nloong/sqlike/v2/sql/expr" 10 | ) 11 | ``` 12 | 13 | | Function name | Example | SQL | 14 | | --------------------- | ------------------------------------------------------------------------ | ------------------------------------------------- | 15 | | `expr.Raw` | expr.Raw("\`Column\` LIKE '%ok%'") | \`Column\` LIKE '%ok%' | 16 | | `expr.Column` | expr.Column("A") | \`A\` | 17 | | `expr.Equal` | expr.Equal("Column", "value") | \`Column\` = 'value' | 18 | | `expr.NotEqual` | expr.NotEqual("Column", "value") | \`Column\` != 'value' | 19 | | `expr.Like` | expr.Like("Column", "value%") | \`Column\` LIKE 'value%' | 20 | | `expr.NotLike` | expr.NotLike("Column", "value%") | \`Column\` NOT LIKE 'value%' | 21 | | `expr.In` | expr.In("Column", []string{"A", "B", "C"}) | \`Column\` IN ('A', 'B', 'C') | 22 | | `expr.NotIn` | expr.NotIn("Column", []string{"A", "B", "C"}) | \`Column\` NOT IN ('A', 'B', 'C') | 23 | | `expr.IsNull` | expr.IsNull("Column") | \`Column\` IS NULL | 24 | | `expr.NotNull` | expr.NotNull("Column") | \`Column\` IS NOT NULL | 25 | | `expr.GreaterThan` | expr.GreaterThan("Column", 1) | \`Column\` > 1 | 26 | | `expr.GreaterOrEqual` | expr.GreaterOrEqual("Column", 1) | \`Column\` >= 1 | 27 | | `expr.LesserThan` | expr.LesserThan("Column", 1) | \`Column\` < 1 | 28 | | `expr.LesserOrEqual` | expr.LesserOrEqual("Column", 1) | \`Column\` <= 1 | 29 | | `expr.Between` | expr.Between("Column", 1, 100) | \`Column\` BETWEEN 1 AND 100 | 30 | | `expr.NotBetween` | expr.NotBetween("Column", 1, 100) | \`Column\` NOT BETWEEN 1 AND 100 | 31 | | `expr.And` | expr.And(expr.Equal("ColumnA", "value"), expr.Equal("ColumnB", "value")) | (\`ColumnA\` = 'value' AND \`ColumnB\` = 'value') | 32 | | `expr.Or` | expr.Or(expr.Equal("ColumnA", "value"), expr.Equal("Column", "value")) | (\`ColumnA\` = 'value' OR \`ColumnB\` = 'value') | 33 | | `expr.Increment` | expr.Increment("Column", 2) | (\`ColumnA\` + 2) | 34 | | `expr.Decrement` | expr.Decrement("Column", 2) | (\`ColumnA\` - 2) | 35 | | `expr.ColumnValue` | expr.ColumnValue("Column", 100) | SET \`Column\` = 100 | 36 | | `expr.Asc` | expr.Asc("ColumnA") | \`ColumnA\` ASC | 37 | | `expr.Desc` | expr.Desc("ColumnA") | \`ColumnA\` DESC | 38 | -------------------------------------------------------------------------------- /versioned_docs/version-1.9/api/operator.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | --- 4 | 5 | # Expression/Operator 6 | 7 | ```go 8 | import ( 9 | "github.com/si3nloong/sqlike/sql/expr" 10 | ) 11 | ``` 12 | 13 | | Function name | Example | SQL | 14 | | --------------------- | ------------------------------------------------------------------------ | ------------------------------------------------- | 15 | | `expr.Raw` | expr.Raw("\`Column\` LIKE '%ok%'") | \`Column\` LIKE '%ok%' | 16 | | `expr.Column` | expr.Column("A") | \`A\` | 17 | | `expr.Equal` | expr.Equal("Column", "value") | \`Column\` = 'value' | 18 | | `expr.NotEqual` | expr.NotEqual("Column", "value") | \`Column\` != 'value' | 19 | | `expr.Like` | expr.Like("Column", "value%") | \`Column\` LIKE 'value%' | 20 | | `expr.NotLike` | expr.NotLike("Column", "value%") | \`Column\` NOT LIKE 'value%' | 21 | | `expr.In` | expr.In("Column", []string{"A", "B", "C"}) | \`Column\` IN ('A', 'B', 'C') | 22 | | `expr.NotIn` | expr.NotIn("Column", []string{"A", "B", "C"}) | \`Column\` NOT IN ('A', 'B', 'C') | 23 | | `expr.IsNull` | expr.IsNull("Column") | \`Column\` IS NULL | 24 | | `expr.NotNull` | expr.NotNull("Column") | \`Column\` IS NOT NULL | 25 | | `expr.GreaterThan` | expr.GreaterThan("Column", 1) | \`Column\` > 1 | 26 | | `expr.GreaterOrEqual` | expr.GreaterOrEqual("Column", 1) | \`Column\` >= 1 | 27 | | `expr.LesserThan` | expr.LesserThan("Column", 1) | \`Column\` < 1 | 28 | | `expr.LesserOrEqual` | expr.LesserOrEqual("Column", 1) | \`Column\` <= 1 | 29 | | `expr.Between` | expr.Between("Column", 1, 100) | \`Column\` BETWEEN 1 AND 100 | 30 | | `expr.NotBetween` | expr.NotBetween("Column", 1, 100) | \`Column\` NOT BETWEEN 1 AND 100 | 31 | | `expr.And` | expr.And(expr.Equal("ColumnA", "value"), expr.Equal("ColumnB", "value")) | (\`ColumnA\` = 'value' AND \`ColumnB\` = 'value') | 32 | | `expr.Or` | expr.Or(expr.Equal("ColumnA", "value"), expr.Equal("Column", "value")) | (\`ColumnA\` = 'value' OR \`ColumnB\` = 'value') | 33 | | `expr.Increment` | expr.Increment("Column", 2) | (\`ColumnA\` + 2) | 34 | | `expr.Decrement` | expr.Decrement("Column", 2) | (\`ColumnA\` - 2) | 35 | | `expr.ColumnValue` | expr.ColumnValue("Column", 100) | SET \`Column\` = 100 | 36 | | `expr.Asc` | expr.Asc("ColumnA") | \`ColumnA\` ASC | 37 | | `expr.Desc` | expr.Desc("ColumnA") | \`ColumnA\` DESC | 38 | -------------------------------------------------------------------------------- /docusaurus.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Note: type annotations allow type checking and IDEs autocompletion 3 | 4 | const lightCodeTheme = require("prism-react-renderer/themes/github"); 5 | const darkCodeTheme = require("prism-react-renderer/themes/dracula"); 6 | 7 | /** @type {import('@docusaurus/types').Config} */ 8 | const config = { 9 | title: "sqlike", 10 | tagline: "Elegent SQL ORM in Go.", 11 | url: "https://sqlike.com", 12 | baseUrl: "/", 13 | onBrokenLinks: "throw", 14 | onBrokenMarkdownLinks: "warn", 15 | favicon: "img/favicon.ico", 16 | 17 | // GitHub pages deployment config. 18 | // If you aren't using GitHub pages, you don't need these. 19 | organizationName: "si3nloong", // Usually your GitHub org/user name. 20 | projectName: "sqlike", // Usually your repo name. 21 | 22 | // Even if you don't use internalization, you can use this field to set useful 23 | // metadata like html lang. For example, if your site is Chinese, you may want 24 | // to replace "en" with "zh-Hans". 25 | i18n: { 26 | defaultLocale: "en", 27 | locales: ["en", "zh"], 28 | }, 29 | 30 | presets: [ 31 | [ 32 | "classic", 33 | /** @type {import('@docusaurus/preset-classic').Options} */ 34 | ({ 35 | docs: { 36 | sidebarPath: require.resolve("./sidebars.js"), 37 | // Please change this to your repo. 38 | // Remove this to remove the "edit this page" links. 39 | 40 | // editUrl: 41 | // "https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/", 42 | }, 43 | theme: { 44 | customCss: require.resolve("./src/css/custom.css"), 45 | }, 46 | }), 47 | ], 48 | ], 49 | 50 | themeConfig: 51 | /** @type {import('@docusaurus/preset-classic').ThemeConfig} */ 52 | ({ 53 | navbar: { 54 | title: "SQLike", 55 | logo: { 56 | alt: "sqlike", 57 | src: "img/logo.svg", 58 | }, 59 | items: [ 60 | { 61 | type: "docsVersionDropdown", 62 | }, 63 | { 64 | type: "localeDropdown", 65 | }, 66 | { 67 | type: "doc", 68 | docId: "intro", 69 | position: "left", 70 | label: "Tutorial", 71 | }, 72 | { 73 | href: "https://github.com/si3nloong/sqlike", 74 | label: "GitHub", 75 | position: "right", 76 | }, 77 | ], 78 | }, 79 | footer: { 80 | style: "dark", 81 | links: [ 82 | { 83 | title: "Docs", 84 | items: [ 85 | { 86 | label: "Tutorial", 87 | to: "/docs/intro", 88 | }, 89 | ], 90 | }, 91 | // { 92 | // title: "Community", 93 | // items: [ 94 | // { 95 | // label: "Stack Overflow", 96 | // href: "https://stackoverflow.com/questions/tagged/docusaurus", 97 | // }, 98 | // { 99 | // label: "Discord", 100 | // href: "https://discordapp.com/invite/docusaurus", 101 | // }, 102 | // { 103 | // label: "Twitter", 104 | // href: "https://twitter.com/docusaurus", 105 | // }, 106 | // ], 107 | // }, 108 | { 109 | title: "More", 110 | items: [ 111 | // { 112 | // label: "Blog", 113 | // to: "/blog", 114 | // }, 115 | { 116 | label: "GitHub", 117 | href: "https://github.com/si3nloong/sqlike", 118 | }, 119 | ], 120 | }, 121 | ], 122 | copyright: `Copyright © ${new Date().getFullYear()} si3nloong.`, 123 | }, 124 | prism: { 125 | theme: lightCodeTheme, 126 | darkTheme: darkCodeTheme, 127 | }, 128 | }), 129 | }; 130 | 131 | module.exports = config; 132 | -------------------------------------------------------------------------------- /static/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /static/img/schema_structure.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 |
11 |
:
12 |
13 |
14 |
15 | : 16 |
17 |
18 | 19 | 20 | 21 | 22 |
23 |
24 |
sqlike
25 |
26 |
27 |
28 | sqlike 29 |
30 |
31 | 32 | 33 | 34 | 35 |
36 |
37 |
id
38 |
39 |
40 |
41 | id 42 |
43 |
44 | 45 | 46 | 47 | 48 |
49 |
50 |
,
51 |
52 |
53 |
54 | , 55 |
56 |
57 | 58 | 59 | 60 | 61 |
62 |
63 |
primary_key,auto_increment,...
64 |
65 |
66 |
67 | primary_key,auto_increment,... 68 |
69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 |
77 |
78 |
Column Name
79 |
80 |
81 |
82 | Column... 83 |
84 |
85 | 86 | 87 | 88 | 89 |
90 |
91 |
Column Modifier
92 |
93 |
94 |
95 | Column... 96 |
97 |
98 | 99 | 100 | 101 | 102 |
103 |
104 |
Scheme
105 |
106 |
107 |
108 | Scheme 109 |
110 |
111 |
112 | 113 | 114 | 115 | Text is not SVG - cannot display 116 | 117 | 118 |
--------------------------------------------------------------------------------