gg-mysql-connector 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +10 -10
  2. package/package.json +1 -1
  3. package/readme2.md +0 -117
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # gg-mysql-connector
1
+ # GG-Mysql-Connector
2
2
 
3
3
  **`gg-mysql-connector`** is an intuitive MySQL model creator designed to simplify database management and operations by synchronizing TypeScript models with MySQL tables. This package allows you to declare and manage your MySQL database structure programmatically, with strong type enforcement.
4
4
 
@@ -95,19 +95,19 @@ const db = new GGMySQLConnector<app_INF>({
95
95
  await db.init()
96
96
 
97
97
  // Select operations
98
- let result_1 = await db.select("item")
99
- let result_2 = await db.selectByID("user", 2)
100
- let result_3 = await db.selectByMatchParams("item", { id: 5 })
101
- let result_4 = await db.selectByMatchParams("item", { name: "pen", price: 3 })
98
+ const result_1 = await db.select("item")
99
+ const result_2 = await db.selectByID("user", 2)
100
+ const result_3 = await db.selectByMatchParams("item", { id: 5 })
101
+ const result_4 = await db.selectByMatchParams("item", { name: "pen", price: 3 })
102
102
 
103
103
  // Update operations
104
- let result_5 = await db.update("user", { id: 3, name: "Tony" })
105
- let result_6 = await db.update("item", { id: 3, price: 4, name: "Ruler" })
106
- let result_7 = await db.updateOnlyID("item", { oldID: 7, newID: 4 })
104
+ const result_5 = await db.update("user", { id: 3, name: "Tony" })
105
+ const result_6 = await db.update("item", { id: 3, price: 4, name: "Ruler" })
106
+ const result_7 = await db.updateOnlyID("item", { oldID: 7, newID: 4 })
107
107
 
108
108
  // Delete operations
109
- let result_8 = await db.deleteByID("item", 5)
110
- let result_9 = await db.deleteByMatchParams("item", { name: "pen", price: 5 })
109
+ const result_8 = await db.deleteByID("item", 5)
110
+ const result_9 = await db.deleteByMatchParams("item", { name: "pen", price: 5 })
111
111
 
112
112
  // raw query
113
113
  const result_10 = await db.query("SELECT * FROM item where id = ?", [5])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme2.md DELETED
@@ -1,117 +0,0 @@
1
- # gg-mysql-connector
2
-
3
- gg-mysql-connector is an intuitive MySQL model creator designed to simplify database management and operations by synchronizing TypeScript models with MySQL tables. This package allows you to declare and manage your MySQL database structure programmatically while enforcing strong type constraints.
4
-
5
- Features
6
-
7
- • Declare Database Structure: Easily define your database tables and columns as TypeScript variables.
8
- • Sync Database Structure: Automatically synchronize your defined structures with the actual MySQL database.
9
- • Automated View Management: Automatically create or update SQL views based on your declarations.
10
- • Generate TypeScript Models: Generate interfaces that mirror your MySQL structure, ensuring type-safe operations.
11
- • Type-Safe MySQL Connector: Provides a type-enforced MySQL connector with basic functions such as:
12
- • Performing CRUD operations (Select, Update, Delete)
13
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install gg-mysql-connector
18
- ```
19
-
20
- ## 1. Declare your model
21
-
22
- ```typescript
23
- import { MyModel } from "../myModel"
24
-
25
- const model: MyModel[] = [
26
- {
27
- tableName: "user",
28
- columns: [
29
- {
30
- COLUMN_NAME: "id",
31
- DATA_TYPE: "int",
32
- AUTO_INCREMENT: true,
33
- },
34
- {
35
- COLUMN_NAME: "name",
36
- DATA_TYPE: "varchar(512)",
37
- },
38
- ],
39
- },
40
- {
41
- tableName: "item",
42
- columns: [
43
- {
44
- COLUMN_NAME: "id",
45
- DATA_TYPE: "int",
46
- AUTO_INCREMENT: true,
47
- },
48
- {
49
- COLUMN_NAME: "name",
50
- DATA_TYPE: "varchar(512)",
51
- },
52
- {
53
- COLUMN_NAME: "price",
54
- DATA_TYPE: "float",
55
- },
56
- {
57
- COLUMN_NAME: "status",
58
- DATA_TYPE: "varchar(64)",
59
- POSSIBLE_VALUE: ["ACTIVE", "DISABLE"],
60
- },
61
- {
62
- COLUMN_NAME: "description",
63
- DATA_TYPE: "varchar(512)",
64
- },
65
- ],
66
- },
67
- ]
68
- ```
69
-
70
- ## 2. Sync model and views to mysql and generate model interface file
71
-
72
- ```typescript
73
- const migrator = new ModelGenerator(
74
- {
75
- host: "you-host",
76
- user: "user",
77
- password: "password",
78
- database: "test_ggdb_connector",
79
- },
80
- model
81
- )
82
- await migrator.init()
83
- await migrator.pushModelToDB()
84
- await migrator.pushViewToDB("./views")
85
- await migrator.generateModelInterface({
86
- appName: "app",
87
- model: model,
88
- ouputDirectory: ["./"],
89
- })
90
- process.exit()
91
- ```
92
-
93
- ## 3. CRUD with type enforced
94
-
95
- ```typescript
96
- // app_INF is an interface that you generated from step 2
97
- import app_INF from "your-output-directory/app_INF"
98
- const db = new GGMySQLConnector<app_INF>({
99
- host: "you-host",
100
- user: "user",
101
- password: "password",
102
- database: "test_ggdb_connector",
103
- })
104
- await db.init()
105
-
106
- let result_1 = await db.select("item")
107
- let result_2 = await db.selectByID("user", 2)
108
- let result_3 = await db.selectByMatchParams("item", { id: 5 })
109
- let result_4 = await db.selectByMatchParams("item", { name: "pen", price: 3 })
110
-
111
- let result_5 = await db.update("user", { id: 3, name: "tony" })
112
- let result_6 = await db.update("item", { id: 3, price: 4, name: "ruler" })
113
- let result_7 = await db.updateOnlyID("item", { oldID: 7, newID: 4 })
114
-
115
- let result_8 = await db.deleteByID("item", 5)
116
- let result_9 = await db.deleteByMatchParams("item", { name: "pen", price: 5 })
117
- ```