This commit is contained in:
Sam 2025-04-13 14:27:54 +02:00
parent 4b0ed63a39
commit 5c6091286a
43 changed files with 713 additions and 1636 deletions

View File

@ -125,9 +125,9 @@
"23": {
"js": [
{
"file": "assets/js/d7af1896.f2a88258.js",
"hash": "8e044d38139c814a",
"publicPath": "/awSQL/assets/js/d7af1896.f2a88258.js"
"file": "assets/js/d7af1896.82e89304.js",
"hash": "ad1669fcf655ee54",
"publicPath": "/awSQL/assets/js/d7af1896.82e89304.js"
}
]
},
@ -161,9 +161,9 @@
"53": {
"js": [
{
"file": "assets/js/7e36430b.8960b934.js",
"hash": "47e891266c5d8aab",
"publicPath": "/awSQL/assets/js/7e36430b.8960b934.js"
"file": "assets/js/7e36430b.b354b9c9.js",
"hash": "718a83e1c5929ee1",
"publicPath": "/awSQL/assets/js/7e36430b.b354b9c9.js"
}
]
},
@ -188,18 +188,18 @@
"129": {
"js": [
{
"file": "assets/js/3ee20894.dd13f441.js",
"hash": "0d0aefff28794409",
"publicPath": "/awSQL/assets/js/3ee20894.dd13f441.js"
"file": "assets/js/3ee20894.1f6e2c20.js",
"hash": "0879b98420fb13b7",
"publicPath": "/awSQL/assets/js/3ee20894.1f6e2c20.js"
}
]
},
"162": {
"js": [
{
"file": "assets/js/23e85390.2618872f.js",
"hash": "c24136d1e49b39f5",
"publicPath": "/awSQL/assets/js/23e85390.2618872f.js"
"file": "assets/js/23e85390.a0249aa2.js",
"hash": "7639c0d4b7f0342d",
"publicPath": "/awSQL/assets/js/23e85390.a0249aa2.js"
}
]
},
@ -224,45 +224,45 @@
"269": {
"js": [
{
"file": "assets/js/e2f8b94f.ade39698.js",
"hash": "06611cfa27181e77",
"publicPath": "/awSQL/assets/js/e2f8b94f.ade39698.js"
"file": "assets/js/e2f8b94f.e1eb5318.js",
"hash": "4d411fc486116b50",
"publicPath": "/awSQL/assets/js/e2f8b94f.e1eb5318.js"
}
]
},
"294": {
"js": [
{
"file": "assets/js/24da6c76.00f1b2a5.js",
"hash": "eb0c867e8e897139",
"publicPath": "/awSQL/assets/js/24da6c76.00f1b2a5.js"
"file": "assets/js/24da6c76.159e5a29.js",
"hash": "f0d831d470e02e50",
"publicPath": "/awSQL/assets/js/24da6c76.159e5a29.js"
}
]
},
"344": {
"js": [
{
"file": "assets/js/2ab12074.600c5927.js",
"hash": "3a84469be2454a6a",
"publicPath": "/awSQL/assets/js/2ab12074.600c5927.js"
"file": "assets/js/2ab12074.76390b1f.js",
"hash": "b225c75845ee909a",
"publicPath": "/awSQL/assets/js/2ab12074.76390b1f.js"
}
]
},
"354": {
"js": [
{
"file": "assets/js/runtime~main.0c00e2e3.js",
"hash": "59d21cc22876cc4f",
"publicPath": "/awSQL/assets/js/runtime~main.0c00e2e3.js"
"file": "assets/js/runtime~main.4e405e56.js",
"hash": "c937470a9f515f5f",
"publicPath": "/awSQL/assets/js/runtime~main.4e405e56.js"
}
]
},
"388": {
"js": [
{
"file": "assets/js/c8ec3168.b94e6135.js",
"hash": "d8c4e382c8959338",
"publicPath": "/awSQL/assets/js/c8ec3168.b94e6135.js"
"file": "assets/js/c8ec3168.0f7a63be.js",
"hash": "16bcf9cadcb1e217",
"publicPath": "/awSQL/assets/js/c8ec3168.0f7a63be.js"
}
]
},
@ -278,9 +278,9 @@
"468": {
"js": [
{
"file": "assets/js/7617dfbd.053daa6b.js",
"hash": "cc722a79e9b3e8c6",
"publicPath": "/awSQL/assets/js/7617dfbd.053daa6b.js"
"file": "assets/js/7617dfbd.263a6f48.js",
"hash": "03bb6f213164a1b1",
"publicPath": "/awSQL/assets/js/7617dfbd.263a6f48.js"
}
]
},
@ -296,27 +296,27 @@
"550": {
"js": [
{
"file": "assets/js/763f4ffe.337527a1.js",
"hash": "e3c2820da330129a",
"publicPath": "/awSQL/assets/js/763f4ffe.337527a1.js"
"file": "assets/js/763f4ffe.a8324a68.js",
"hash": "d823e39604de0641",
"publicPath": "/awSQL/assets/js/763f4ffe.a8324a68.js"
}
]
},
"579": {
"js": [
{
"file": "assets/js/a6964e95.5827e567.js",
"hash": "0c3796f90d6e88c1",
"publicPath": "/awSQL/assets/js/a6964e95.5827e567.js"
"file": "assets/js/a6964e95.e1343f6c.js",
"hash": "6c5063e85acf3a59",
"publicPath": "/awSQL/assets/js/a6964e95.e1343f6c.js"
}
]
},
"582": {
"js": [
{
"file": "assets/js/b5207823.d5f3dd71.js",
"hash": "2b044c0b1bfb4ab9",
"publicPath": "/awSQL/assets/js/b5207823.d5f3dd71.js"
"file": "assets/js/b5207823.cdd836e5.js",
"hash": "1549c4e7a13ddc9b",
"publicPath": "/awSQL/assets/js/b5207823.cdd836e5.js"
}
]
},
@ -413,9 +413,9 @@
"960": {
"js": [
{
"file": "assets/js/58de6db1.acbf3523.js",
"hash": "b61a717ddbead4b3",
"publicPath": "/awSQL/assets/js/58de6db1.acbf3523.js"
"file": "assets/js/58de6db1.99333c32.js",
"hash": "1beaa9115381c47e",
"publicPath": "/awSQL/assets/js/58de6db1.99333c32.js"
}
]
},
@ -431,9 +431,9 @@
"976": {
"js": [
{
"file": "assets/js/0e384e19.c65359e3.js",
"hash": "5e2203b0e107c819",
"publicPath": "/awSQL/assets/js/0e384e19.c65359e3.js"
"file": "assets/js/0e384e19.45d51a01.js",
"hash": "a76a38834ecc3bcf",
"publicPath": "/awSQL/assets/js/0e384e19.45d51a01.js"
}
]
}

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"id": "classes/alter-table",
"title": "AlterTable",
"description": "Alters a table.",
"description": "Modifies an existing table by altering its structure.",
"source": "@site/docs/classes/alter-table.md",
"sourceDirName": "classes",
"slug": "/classes/alter-table",

View File

@ -1,7 +1,7 @@
{
"id": "classes/awsql",
"title": "awSQL",
"description": "This is the default exported module that holds all Instances and manages them.",
"description": "The default exported module that holds and manages all database instances globally.",
"source": "@site/docs/classes/awsql.md",
"sourceDirName": "classes",
"slug": "/classes/awsql",

View File

@ -1,7 +1,7 @@
{
"id": "classes/create-table",
"title": "CreateTable",
"description": "Creates a new table with defined structure.",
"description": "Creates a new table with a defined structure.",
"source": "@site/docs/classes/create-table.md",
"sourceDirName": "classes",
"slug": "/classes/create-table",

View File

@ -1,7 +1,7 @@
{
"id": "classes/instance",
"title": "Instance",
"description": "Holds connection data and is the gateway to performing queries.",
"description": "Handles connection data and serves as the gateway for performing queries.",
"source": "@site/docs/classes/instance.md",
"sourceDirName": "classes",
"slug": "/classes/instance",

View File

@ -1,7 +1,7 @@
{
"id": "classes/structure",
"title": "Structure",
"description": "Defines a new Table structure.",
"description": "Defines a new table structure for managing columns efficiently.",
"source": "@site/docs/classes/structure.md",
"sourceDirName": "classes",
"slug": "/classes/structure",

View File

@ -1,7 +1,7 @@
{
"id": "classes/update",
"title": "Update",
"description": "Performs a query to update data in a table.",
"description": "Executes a query to update data in a table.",
"source": "@site/docs/classes/update.md",
"sourceDirName": "classes",
"slug": "/classes/update",

View File

@ -1,7 +1,7 @@
{
"id": "intro",
"title": "Introduction",
"description": "This documentation is still in development.",
"description": "awSQL is a fast and reliable database query tool designed to:",
"source": "@site/docs/intro.md",
"sourceDirName": ".",
"slug": "/",

View File

@ -1,7 +1,7 @@
{
"id": "typedefs/column-structure",
"title": "ColumnStructure",
"description": "Object",
"description": "Type: Object",
"source": "@site/docs/typedefs/column-structure.md",
"sourceDirName": "typedefs",
"slug": "/typedefs/column-structure",

View File

@ -1,7 +1,7 @@
{
"id": "typedefs/constraint-options",
"title": "ConstraintOptions",
"description": "Object",
"description": "Type: Object",
"source": "@site/docs/typedefs/constraint-options.md",
"sourceDirName": "typedefs",
"slug": "/typedefs/constraint-options",

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v3.7.0">
<title data-rh="true">awSQL Documentation</title><meta data-rh="true" property="og:title" content="awSQL Documentation"><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://your-docusaurus-site.example.com/awSQL/404.html"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><link data-rh="true" rel="icon" href="/awSQL/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://your-docusaurus-site.example.com/awSQL/404.html"><link data-rh="true" rel="alternate" href="https://your-docusaurus-site.example.com/awSQL/404.html" hreflang="en"><link data-rh="true" rel="alternate" href="https://your-docusaurus-site.example.com/awSQL/404.html" hreflang="x-default"><link rel="stylesheet" href="/awSQL/assets/css/styles.e478e7bb.css">
<script src="/awSQL/assets/js/runtime~main.0c00e2e3.js" defer="defer"></script>
<script src="/awSQL/assets/js/runtime~main.4e405e56.js" defer="defer"></script>
<script src="/awSQL/assets/js/main.761e9406.js" defer="defer"></script>
</head>
<body class="navigation-with-keyboard">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,20 +4,24 @@ sidebar_position: 9
# AlterTable
Alters a table.
Modifies an existing table by altering its structure.
---
## Methods
---
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
Selects a different database for this query.
Switches to a different database for this query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |
| `database` | __String__ | The name of the database to select. |
**Returns**
@ -28,17 +32,18 @@ Selects a different database for this query.
### structure()
&rarr; (`structure` = [Structure](./structure)) &rarr; `this`
The new desired structure for the table to get.
Defines the new table structure.
- Drops columns that are existing in the current table but not in the given structure
- Adds columns that are missing in the current table
- Modifies all other columns where at least one datatype is not matching
**Behavrior**
- **Drops** columns that exist in the current table but not in the new structure.
- **Adds** missing columns.
- **Modifies** columns where datatypes differ.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `structure` | [Structure](./structure) | New structure definition for the table |
| `structure` | [Structure](./structure) | The new structure definition. |
**Returns**
@ -49,14 +54,14 @@ The new desired structure for the table to get.
### execute()
`async` &rarr; () &rarr; [Instance.checkStructure()](./instance#checkstructure)
:::warning Possible crash
[structure()](#structure) must always be given.
:::
Executes the prepared table alteration query.
Executes the prepared query.
:::warning Important
The [structure()](#structure) method **must** be called before executing, or the operation may fail.
:::
**Returns**
&rarr; [Instance.checkStructure()](./instance#checkstructure) - Checks the structure afterwards and returns the check result
&rarr; [Instance.checkStructure()](./instance#checkstructure) - Performs a post-execution structure check and returns the result.
***

View File

@ -4,38 +4,40 @@ sidebar_position: 1
# awSQL
This is the default exported module that holds all Instances and manages them.
The default exported module that holds and manages all database instances globally.
It does not provide any functionality on top of managing instances globally.
It does not provide any additional functionality beyond managing instances.
---
## Methods
---
### createInstance()
&rarr; (`hostname` = __String__, `username` = __String__, `password` = __String__, `options`? = \{`charset`?: __String__, `defaultDatabase`?: __String__, `multipleStatements`?: __Boolean__, `insecureAuth`?: __Boolean__, `customIdentifier`?: __String__, `isDefault`?: __Boolean__\}) &rarr; [Instance](./instance)
Creates a new instance to connect to a database.
Creates a new database connection instance.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `hostname` | __String__ | The hostname where the database is hosted |
| `username` | __String__ | Username to connect with |
| `password` | __String__ | Password |
| `options` __optional__ | __Object__ | Additional options |
| &rarr; `options.charset` __optional__ | __String__ | The charset to use |
| &rarr; `options.defaultDatabase` __optional__ | __String__ | The default database to select for queries |
| &rarr; `options.multipleStatements` __optional__ | __Boolean__ | Whether to allow multiple statements in a single query. Defaults to `false` |
| &rarr; `options.insecureAuth` __optional__ | __Boolean__ | Whether insecure authentication methods should be allowed. Defaults to `false` |
| &rarr; `options.customIdentifier` __optional__ | __String__ | Sets a custom identifier for this instance. Instances can be fetched by [getInstance()](#getInstance) with this identifier. If not set, the identifier will be "`username`@`hostname`" by default. |
| &rarr; `options.isDefault` __optional__ | __Boolean__ | Whether this instance is returned by default via [getInstance()](#getInstance) if the given identifier is empty or not retrievable |
| `hostname` | __String__ | The database hostname. |
| `username` | __String__ | The username for authentication. |
| `password` | __String__ | The password for authentication. |
| `options` __optional__ | __Object__ | Additional settings for the instance. |
| &rarr; `options.charset` __optional__ | __String__ | The character set to use. |
| &rarr; `options.defaultDatabase` __optional__ | __String__ | Default database for queries. |
| &rarr; `options.multipleStatements` __optional__ | __Boolean__ | Allow multiple SQL statements in a single query (default: `false`). |
| &rarr; `options.insecureAuth` __optional__ | __Boolean__ | Enables insecure authentication methods (default: `false`). |
| &rarr; `options.customIdentifier` __optional__ | __String__ | Custom instance identifier. Defaults to `username@hostname`. |
| &rarr; `options.isDefault` __optional__ | __Boolean__ | Marks this instance as the default when no identifier is provided in [getInstance()](#getinstance). |
:::warning Possible errors
This might crash if either of these situations happen:
- `password` is empty
- `username` is empty
- An instance with the same `identifier` already exists
This method **may crash** if:
- `password` or `username` is empty.
- An instance with the same `identifier` already exists.
:::
**Returns**
@ -47,56 +49,53 @@ This might crash if either of these situations happen:
### getInstance()
&rarr; (`identifier`? = __String__) &rarr; [Instance](./instance) / __undefined__
Returns an already defined instance with the given `identifier`.
Retrieves an existing database instance by its `identifier`.
If a default instance was set it returns said instance if the `identifier` is empty.
If no identifier is provided and a default instance exists, it returns the default instance.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `identifier` __optional__ | __String__ | The instance name to retrieve. Note: If not set with `options.customIdentifier` upon creation instances will be identified by "`username`@`hostname`".<br/> If not given it returns the defined default instance. |
| `identifier` __optional__ | __String__ | The name of the instance to retrieve. If no explicitly set with `customIdentifier`, instances are identified as `username@hostname`. |
**Returns**
- [Instance](./instance) - Instance was found
- __undefined__
- [Instance](./instance) - if found.
- __undefined__ - if no instance matches the identifier.
***
### listInstances()
&rarr; () &rarr; __Array__\<__String__\>
Returns a list of defined instance identifiers
Returns a list of all defined instance identifiers.
**Returns**
&rarr; __Array__\<__String__\>
&rarr; __Array__\<__String__\> - A list of instance identifiers.
***
### deleteInstance()
&rarr; (`identifier` = __String__) &rarr; __true__
Deletes an instance and closes any open connection
Deletes an existing instance and closes its database connection.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `identifier` __optional__ | __String__ | The instance to delete. Note: If not set with `options.customIdentifier` upon creation instances will be identified by "`username`@`hostname`". |
| `identifier` __optional__ | __String__ | The identifier of the instance to delete. If `customIdentifier` was not set, use `username@hostname`. |
:::warning Possible crash
This might crash if either of these situations happen:
- `identifier` is empty
- To delete the default instance you must provide the `identifier` of the default instance.
- `identifier` is not of type __String__
- No instance with the given `identifier` was found
:::warning Possible Error
This method **may crash** if:
- `identifier` is empty.
- To delete the default instance, provide its `identifier`.
- `identifier` is not a `String`.
- No instance with the given `identifier` exists.
:::
**Returns**
&rarr; __true__
&rarr; __true__ - Awayls returns `true`. Errors will cause an exception instead.
:::info
Always returns true, as it will throw if any error happens to be sure any deletion was intended and correctly called.
:::
---

View File

@ -4,20 +4,24 @@ sidebar_position: 8
# CreateTable
Creates a new table with defined structure.
Creates a new table with a defined structure.
---
## Methods
---
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
Selects a different database for this query.
Selects a specific database for the query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |
| `database` | __String__ | The name of the database to select. |
**Returns**
@ -34,7 +38,7 @@ Sets the name of the new table.
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name for the table |
| `name` | __String__ | The name of the table. |
**Returns**
@ -45,13 +49,13 @@ Sets the name of the new table.
### structure()
&rarr; (`structure` = [Structure](./structure)) &rarr; `this`
The desired structure for the table to get.
Defines the desired structure for the new table.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `structure` | [Structure](./structure) | Structure for the table. |
| `structure` | [Structure](./structure) | The structure of the table. |
**Returns**
@ -62,11 +66,11 @@ The desired structure for the table to get.
### execute()
`async` &rarr; () &rarr; [OkPacket](../typedefs/okpacket)
:::warning Possible crash
[structure()](#structure) must always be given.
:::
Executes the query and creates the table.
Executes the prepared query.
:::warning Possible Crash
The [structure()](#structure) method **must** be called before execution.
:::
**Returns**

View File

@ -7,23 +7,27 @@ sidebar_position: 5
Performs a query to delete rows from a table.
:::warning Possible crash
To prevent accidental deletion of all rows, this will throw an error on [execute()](#execute) if no [where()](#where) was defined.
To **prevent accidental deletion of all rows**, an error will be thrown on [execute()](#execute) if no [where()](#where) clause is defined.
To enable the deletion of all rows use [force()](#force).
To **explicitly allow deletion of all rows**, use [force()](#force).
:::
---
## Methods
---
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
Selects a different database for this query.
Sets the database for this query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |
| `database` | __String__ | The database name to select. |
**Returns**
@ -34,17 +38,22 @@ Selects a different database for this query.
### where()
&rarr; (`string` = __String__, `values` = __Array__\<__any__\>) &rarr; `this`
Adds a where-clause to the query
- Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
- If you are using joins, specify the table and column together: table.column
Addsa `WHERE` clause to the delete query.
- **Use placeholders (`?`)** in the condition string and provide values in the `values` array **to prevent SQL injection**.
- If using **joins**, specify the table and column together: `"table.column"`.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `string` | __String__ | The where-clause as a string with ? representing each values. |
| `values` | __Array__\<__any__\> | Array containing values replacing the ? in the string (from left to right) |
| `string` | __String__ | SQL `WHERE` condition with `?` placeholders. |
| `values` | __Array__\<__any__\> | Values replacing `?`, in left-to-right order. |
**Example Usage**
```js showLineNumbers
.delete().where("id = ?", [5])
```
**Returns**
@ -55,7 +64,11 @@ Adds a where-clause to the query
### force()
&rarr; () &rarr; `this`
Enables deletion of all rows.
**Enables deletion of all rows**, overriding the safeguard in [execute()](#execute).
:::danger Use with Caution
Calling [execute()](#execute) after [force()](#force) will delete **all rows** in the table.
:::
**Returns**
@ -66,7 +79,7 @@ Enables deletion of all rows.
### execute()
`async` &rarr; () &rarr; [OkPacket](../typedefs/okpacket)
Executes the prepared query.
Executes the prepared `DELETE` query.
**Returns**

View File

@ -6,18 +6,22 @@ sidebar_position: 4
Performs a query to insert new data into a table.
---
## Methods
---
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
Selects a different database for this query.
Sets the database for this query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |
| `database` | __String__ | Name of the database to select. |
**Returns**
@ -28,13 +32,23 @@ Selects a different database for this query.
### data()
&rarr; (`objects` = __Array__\<__Object__\>) &rarr; `this`
The data (rows) to insert.
Defines the data (rows) to insert.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `objects` | __Array__\<__Object__\> | Array containing objects to insert, where the key represent the column-name. All objects must have the same key-structure! |
| `objects` | __Array__\<__Object__\> | Array of objects where **keys represent column names**. All objects **must have the same structure**. |
**Example Usage**
```js showLineNumbers
.insert()
.data([
{ id: 1, name: "Alice", age: 25 },
{ id: 2, name: "Bob", age: 30 }
])
```
**Returns**
@ -45,7 +59,7 @@ The data (rows) to insert.
### execute()
`async` &rarr; () &rarr; [OkPacket](../typedefs/okpacket)
Executes the prepared query.
Executes the prepared `INSERT` query.
**Returns**

View File

@ -4,70 +4,76 @@ sidebar_position: 2
# Instance
Holds connection data and is the gateway to performing queries.
Handles connection data and serves as the gateway for performing queries.
Instances can be managed via the default export [awSQL](./awsql)
Instances can be managed globally via [awSQL](../classes/awsql).
---
## Methods
---
### connect()
`Promise` &rarr; () &rarr; __String__
Connects the instance.
Establishes a connection to the database.
:::warning Possible crash
Throws an error whenever the connection fails with an error
:::warning Possible Errors
Throws an error if the connection fails.
:::
**Returns**
&rarr; __String__ - A connection string in the following format: "Connected to `host` with user `user`"
&rarr; __String__ - Connection confirmation in the format: `"Connected to host with user user"`
***
### destroy()
&rarr; () &rarr; __true__
Destroys the connection
Destroys the connection and releases resources.
**Returns**
&rarr; __true__
&rarr; __true__ - Always returns `true` unless an error occurs.
***
### queryRaw()
`async` &rarr; (`queryString` = __String__, `values`? = __Array__\<__any__\>) &rarr; __any__
Performs a raw query with the given sql-string.
Executes a raw SQL query.
To prevent sql-injections use ? and push your values in order into the `values` array.
:::tip Security Tip
Use `?` placeholders and pass values seperately to prevent SQL injection.
:::
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `queryString` | __String__ | The sql-query to perform |
| `values` | __Array__\<__any__\> | ? in the query string will be replaced by this values in order |
| `queryString` | __String__ | SQL query to execute. |
| `values` | __Array__\<__any__\> | Values for placeholders (`?`), in left-to-right order. |
**Returns**
&rarr; __any__ - Whatever the query returns
&rarr; __any__ - Query Result
***
### getDatabases()
`async` &rarr; (`excludeSchema`? = __Boolean__) &rarr; __Array__\<__String__\>
Returns a list of database names the user has access to
Retrieves a list of databases accessible to the user.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `excludeSchema` __option__ | __Boolean__ | Whether to exclude the default database 'information_schema' |
| `excludeSchema` __option__ | __Boolean__ | Excludes `information_schema` if `true` |
**Returns**
&rarr; __Array__\<__String__\>
&rarr; __Array__\<__String__\> - List of database names.
**Example**
@ -86,7 +92,7 @@ console.log(databasesWithoutSchema); // ['awSQL_dev']
### selectDatabase()
&rarr; (`name` = __String__) &rarr; `this`
Selects a default database for future queries
Sets a default database for future queries.
**Parameters**
| Parameter | Type | Description |
@ -102,25 +108,21 @@ Selects a default database for future queries
### getTables()
&rarr; (`database`? = __String__) &rarr; __Array__\<__String__\>
Returns a list of tables for the selected database
Retrieves a list of tables in the selected database.
:::warning Possible crash
`options.multipleStatemens` must have been set to __true__ at creation of this instance for this to work. If not this will throw an error.
:::warning Possible Errors
Requires `options.multipleStatements` set to `true` at instance creation.
:::
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` __optional__ | __String__ | Database to get tables of. Can be empty as long as a default database was set with 'selectDatabase' |
**Returns**
&rarr; __Array__\<__String__\>
**Example**
**Example Usage**
```js showLineNumbers
const tables = await instance.getTables("awSQL_dev"); // Getting tables of database "awSQL_dev"
const tables = await instance.getTables("awSQL_dev");
console.log(tables);
```
```json title="Result" showLineNumbers
[
@ -137,256 +139,50 @@ const tables = await instance.getTables("awSQL_dev"); // Getting tables of datab
***
### select()
&rarr; (`from` = __String__, `...columns`? = __String__) &rarr; [Select](./select)
### Query Builders
These methods return specialized query objects that allow for structured queries:
Prepares a new select query.
**Parameters**
| Parameter | Type | Description |
| Method | Description | Returns |
| -- | -- | -- |
| `from` | __String__ | Name of the table to select from |
| `...columns` __optional__ | __String__ | Names of the columns to include in the query. Leave empty to select all (`*`) |
| `.select(from, ...columns?)` | Prepare a `SELECT` query. | [Select](./select) |
| `.insert(into)` | Prepare an `INSERT` query. | [Insert](./insert) |
| `.delete(from)` | Prepare a `DELETE` query. | [Delete](./delete) |
| `.update(table)` | Prepare an `UPDATE` query. | [Update](./update) |
**Returns**
---
&rarr; [Select](./select)
### Database & Table Management
***
### insert()
&rarr; (`into` = __String__) &rarr; [Insert](./insert)
Prepares a new query to insert data.
**Parameters**
| Parameter | Type | Description |
| Method | Description | Returns |
| -- | -- | -- |
| `into` | __String__ | Name of the table to insert into |
| `.dropDatabase(database)` | Deletes an entire database (*requires admin privileges*). | [OkPacket](../typedefs/okpacket) |
| `.dropTable(table)` | Deletes a table (*default database must be set*). | [OkPacket](../typedefs/okpacket) |
| `.createDatabase(name)` | Creates a new database (*fails if it already exists*). | [OkPacket](../typedefs/okpacket) |
| `.createTable(name)` | Prepares a new table creation query. | [CreateTable](./create-table) |
| `.alterTable(name)` | Prepares a table modification query. | [AlterTable](./alter-table) |
**Returns**
&rarr; [Insert](./insert)
***
### delete()
&rarr; (`from` = __String__) &rarr; [Delete](./delete)
Prepares a new query to delete data.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `from` | __String__ | Name of the table to delete from |
**Returns**
&rarr; [Delete](./delete)
***
### update()
&rarr; (`table` = __String__) &rarr; [Update](./update)
Prepares a new query to update data.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `table` | __String__ | Name of the table to update data of |
**Returns**
&rarr; [Update](./update)
***
### dropDatabase()
`async` &rarr; (`database` = __String__) &rarr; [OkPacket](../typedefs/okpacket)
Drops a whole database
- Requires admin privileges
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | The name of the database to drop |
**Returns**
&rarr; [OkPacket](../typedefs/okpacket)
***
### dropTable()
`async` &rarr; (`table` = __String__) &rarr; [OkPacket](../typedefs/okpacket)
Drops a whole table.
:::warning Possible crash
A default database must be set with [selectDatabase()](#selectdatabase)
:::danger Potential Errors
- Creating a database requires **admin privileges**.
- Dropping a table reqeuires **a default database to be selected**.
:::
**Parameters**
---
| Parameter | Type | Description |
### Structure Management
| Method | Description | Returns |
| -- | -- | -- |
| `table` | __String__ | The name of the table to drop |
| `.createStructure()` | Creates a structure object. | [Structure](./structure) |
| `.getStructure(table, database?)` | Retrieves the structure of a table. | [Structure](./structure) |
| `.checkStructure(table, desiredStructure, database?)` | Compares a table's structure with the expected one. | `{ errors: [], passed: [] }` <br/>✅ If errors.length === 0, the structure is correct. |
**Returns**
---
&rarr; [OkPacket](../typedefs/okpacket)
### Utility Methods
***
### createDatabase()
`async` &rarr; (`name` = __String__) &rarr; [OkPacket](../typedefs/okpacket)
Creates a new database.
:::danger Possible crash
- Requires admin privileges, crashes otherwise
- Crashes if the database already exists
:::
**Parameters**
| Parameter | Type | Description |
| Method | Description | Returns |
| -- | -- | -- |
| `name` | __String__ | The name of the database to create |
| `.total(table)` | Counts total rows in a table. (*Requires a default database*). | `Number` |
| `.isConnected()` | Checks if the instance is connected. | `Boolean` |
**Returns**
&rarr; [OkPacket](../typedefs/okpacket)
***
### createTable()
&rarr; (`name` = __String__) &rarr; [CreateTable](./create-table)
Prepares to create a new table.
:::danger Possible crash
Crashes if the table already exists
:::
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | The name of the table to create |
**Returns**
&rarr; [CreateTable](./create-table)
***
### alterTable()
&rarr; (`name` = __String__) &rarr; [AlterTable](./alter-table)
Prepares to alter a table.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | The name of the table to alter |
**Returns**
&rarr; [AlterTable](./alter-table)
***
### createStructure()
&rarr; () &rarr; [Structure](./structure)
Creates a new structure.
**Returns**
&rarr; [Structure](./structure)
***
### getStructure()
`async` &rarr; (`table` = __String__, `database`? = __String__) &rarr; [Structure](./structure)
Returns the structure object of a table.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `table` | __String__ | The name of the table to get structure of |
| `database` __optional__ | __String__ | Name of the underlying database. Can be empty when a default database was set with [selectDatabase()](#selectdatabase) |
**Returns**
&rarr; [Structure](./structure)
***
### checkStructure()
`async` &rarr; (`table` = __String__, `desiredStructure` = [Structure](./structure), `database`? = __String__) &rarr; __Object__
Checks the structure of a table against a given structure.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `table` | __String__ | The name of the table to check |
| `desiredStructure` | [Structure](./structure) | The structure to check against |
| `database` __optional__ | __String__ | Name of the underlying database. Can be empty when a default database was set with [selectDatabase()](#selectdatabase) |
**Returns**
&rarr; __Object__
```js
{
errors: [<...String>], // Holds error messages
passed: [<...String>] // Holds success messages
}
```
:::info
If `errors.length` is `0` the structure is correct
:::
***
### total()
`async` &rarr; (`table` = __String__) &rarr; __Number__
Returns the total amount of rows of a table.
- A default database must be set
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `table` | __String__ | The name of the table to check. |
**Returns**
&rarr; __Number__
***
### isConnected()
&rarr; () &rarr; __Boolean__
Returns whether the connection has been established.
**Returns**
&rarr; __Boolean__
---

View File

@ -6,8 +6,12 @@ sidebar_position: 3
Performs a query to retrieve data from a table.
---
## Methods
---
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
@ -28,9 +32,7 @@ Selects a different database for this query.
### distinct()
&rarr; () &rarr; `this`
Adds the 'distinct' keyword to this query.
- With 'distinct' only unique values are returned
Ensures that only unique values are returned in the query results.
**Returns**
@ -41,21 +43,21 @@ Adds the 'distinct' keyword to this query.
Scenario: We want to get the `EmployeeID`s of the Employees that have open orders in [Orders](../example-db/Orders)
```js showLineNumbers
const empOrders = await instance.select("Orders", "EmployeeID") // Select table "Orders" and column "EmployeeID"
.distinct() // Only get unique EmployeeIDs
const empOrders = await instance.select("Orders", "EmployeeID") // Selects "EmployeeID" from "Orders"
.distinct() // Ensures unique EmployeeIDs
.execute();
console.log(empOrders);
/*
/* Output:
[
RowDataPacket { EmployeeID: 5 },
RowDataPacket { EmployeeID: 6 },
RowDataPacket { EmployeeID: 4 },
RowDataPacket { EmployeeID: 3 },
RowDataPacket { EmployeeID: 9 },
RowDataPacket { EmployeeID: 1 },
RowDataPacket { EmployeeID: 8 },
RowDataPacket { EmployeeID: 2 },
RowDataPacket { EmployeeID: 7 }
{ EmployeeID: 5 },
{ EmployeeID: 6 },
{ EmployeeID: 4 },
{ EmployeeID: 3 },
{ EmployeeID: 9 },
{ EmployeeID: 1 },
{ EmployeeID: 8 },
{ EmployeeID: 2 },
{ EmployeeID: 7 }
]
*/
```
@ -65,17 +67,16 @@ console.log(empOrders);
### where()
&rarr; (`string` = __String__, `values` = __Array__\<__any__\>) &rarr; `this`
Adds a where-clause to the query
- Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
- If you are using joins, specify the table and column together: table.column
Adds a `WHERE` clause to filter results.
- Use `?` as placeholders in the condition string to prevent SQL injection.
- If using joins, specify columns as `table.column`.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `string` | __String__ | The where-clause as a string with ? representing each values. |
| `values` | __Array__\<__any__\> | Array containing values replacing the ? in the string (from left to right) |
| `string` | __String__ | `WHERE` clause with `?` placeholders for values. |
| `values` | __Array__\<__any__\> | Values to replace `?`, in order. |
**Returns**
@ -86,35 +87,15 @@ Adds a where-clause to the query
Scenario: We only want to get the [Orders](../example-db/Orders) from the Customers with the id `90` and `34`
```js showLineNumbers
const filteredOrders = await instance.select("Orders") // Select table 'Orders'
// Filter by orders where CustomerID are our desired ids.
// Note that the values of ? are pushed in order into the value-array
const filteredOrders = await instance.select("Orders") // Select "Orders" table
.where("CustomerID = ? OR CustomerID = ?", [90, 34])
.execute();
console.log(filteredOrders);
/*
/* Output:
[
RowDataPacket {
OrderID: 10248,
CustomerID: 90,
EmployeeID: 5,
OrderDate: '1996-07-04',
ShipperID: 3
},
RowDataPacket {
OrderID: 10250,
CustomerID: 34,
EmployeeID: 4,
OrderDate: '1996-07-08',
ShipperID: 2
},
RowDataPacket {
OrderID: 10253,
CustomerID: 34,
EmployeeID: 3,
OrderDate: '1996-07-10',
ShipperID: 2
}
{ OrderID: 10248, CustomerID: 90, EmployeeID: 5, OrderDate: '1996-07-04', ShipperID: 3 },
{ OrderID: 10250, CustomerID: 34, EmployeeID: 4, OrderDate: '1996-07-08', ShipperID: 2 },
{ OrderID: 10253, CustomerID: 34, EmployeeID: 3, OrderDate: '1996-07-10', ShipperID: 2 }
]
*/
```
@ -124,17 +105,14 @@ console.log(filteredOrders);
### having()
&rarr; (`string` = __String__, `values` = __Array__\<__any__\>) &rarr; `this`
Same as [where()](#where) but allows for aggregation.
- Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
- If you are using joins, specify the table and column together: table.column
Same as [.where()](#where), but allows filtering after aggregation.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `string` | __String__ | The having-clause with possible aggregation ? representing each values. |
| `values` | __Array__\<__any__\> | Array containing values replacing the ? in the string (from left to right) |
| `string` | __String__ | `HAVING` clause with `?` placeholders.. |
| `values` | __Array__\<__any__\> | Values to replace `?`, in order. |
**Returns**
@ -145,17 +123,15 @@ Same as [where()](#where) but allows for aggregation.
### order()
&rarr; (`column` = __String__, `desc` = __Boolean__, `aggregation` = __Enum__) &rarr; `this`
Adds a new sort order.
- Can be used multiple times to order by multiple columns
Adds sorting to the query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `column` | __String__ | Column to order by |
| `desc` | __Boolean__ | Sort descending? Defaults to `false` |
| `aggregation` | __Enum__ &rarr; `MIN`/`MAX`/`COUNT`/`SUM`/`AVG` | The aggregation type to use |
| `column` | __String__ | Column to order by. |
| `desc` | __Boolean__ | Sort in descending order? Defaults to `false`. |
| `aggregation` | __Enum__ &rarr; `MIN`/`MAX`/`COUNT`/`SUM`/`AVG` | Optional aggregation function. |
**Returns**
@ -166,13 +142,13 @@ Adds a new sort order.
### count()
&rarr; (`doParse` = __Boolean__) &rarr; `this`
Counts the number of entries of the first selected column.
Counts the number of rows in the first selected column.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `doParse` | __Boolean__ | If `true` the query will only return a __Number__ of entries. Defaults to `false`. |
| `doParse` | __Boolean__ | If `true`, returns a number instead of an array. Defaults to `false`. |
**Returns**
@ -189,7 +165,7 @@ Sums numerical rows of the first selected column.
| Parameter | Type | Description |
| -- | -- | -- |
| `doParse` | __Boolean__ | If `true` the query will only return a __Number__ of entries. Defaults to `false`. |
| `doParse` | __Boolean__ | If `true`, returns a number. Defaults to `false`. |
**Returns**
@ -200,13 +176,13 @@ Sums numerical rows of the first selected column.
### avg()
&rarr; (`doParse` = __Boolean__) &rarr; `this`
Averages numerical rows of the first selected column.
Calculates the average value of numerical rows in the first selected column.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `doParse` | __Boolean__ | If `true` the query will only return a __Number__ of entries. Defaults to `false`. |
| `doParse` | __Boolean__ | If `true`, returns a number. Defaults to `false`. |
**Returns**
@ -217,13 +193,13 @@ Averages numerical rows of the first selected column.
### group()
&rarr; (`...columns` = __String__) &rarr; `this`
Groups rows that have the same values into summary rows.
Groups rows by the specified columns.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `...columns` | __String__ | The columns to group by |
| `...columns` | __String__ | Columns to group by. |
**Returns**
@ -234,17 +210,17 @@ Groups rows that have the same values into summary rows.
### join()
&rarr; (`type` = __Enum__, `table` = __String__, `onOriginalColumn` = __String__, `onJoinedColumn` = __String__, `...columns` = __String__) &rarr; `this`
Adds a new join to the query.
Performs a `SQL JOIN`.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `type` | __Enum__ &rarr; `LEFT`/`INNER`/`RIGHT`/`FULL OUTER` | The join type |
| `table` | __String__ | Table to join on |
| `onOriginalColumn` | __String__ | Column name on the original table to check agains |
| `onJoinedColumn` | __String__ | Column name of the join table to check against |
| `...columns` | __String__ | The columns to join. OG-columns must be set! |
| `type` | __Enum__ &rarr; `LEFT`/`INNER`/`RIGHT`/`FULL OUTER` | Type of join. |
| `table` | __String__ | Table to join with. |
| `onOriginalColumn` | __String__ | Column from the original table. |
| `onJoinedColumn` | __String__ | Column from the joined table. |
| `...columns` | __String__ | Columns to select. |
**Returns**
@ -255,18 +231,14 @@ Adds a new join to the query.
### limit()
&rarr; (`number` = __Number__, `offset` = __Number__) &rarr; `this`
Limits the query and specifies an offset to start at.
:::warning
`offset` has no default value and therefore must not be empty!
:::
Limits the number of returned rows and sets an offset.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `number` | __Number__ | Limits the query by specified rows |
| `offset` | __Number__ | Offset to start at. |
| `number` | __Number__ | Maximum rows to return. |
| `offset` | __Number__ | Offset for starting position. |
**Returns**
@ -277,14 +249,14 @@ Limits the query and specifies an offset to start at.
### pagination()
&rarr; (`page` = __Number__, `itemsPerPage` = __Number__) &rarr; `this`
Paginates the query.
Applies pagination to the query results.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `page` | __Number__ | The page to get (Minimum 1) |
| `itemsPerPage` | __Number__ | How many items a page should have |
| `page` | __Number__ | The page number (starting from 1). |
| `itemsPerPage` | __Number__ | Number of items per page. |
**Returns**
@ -295,11 +267,11 @@ Paginates the query.
### execute()
`async` &rarr; () &rarr; __Number__ / __Array__\<__Object__\>
Executes the prepared query.
Executes the query.
**Returns**
&rarr; __Number__ - Numerical results<br/>
&rarr; __Array__\<__Object__\> - Row data
&rarr; __Number__ - if (`doParse` is `true`)<br/>
&rarr; __Array__\<__Object__\> - Query Result
***

View File

@ -4,48 +4,52 @@ sidebar_position: 7
# Structure
Defines a new Table structure.
Defines a new table structure for managing columns efficiently.
---
## Methods
---
### constructor()
&rarr; (`tableDescription`? = __Array__\<[ColumnStructure](../typedefs/column-structure)\>) &rarr; `this`
Create a new `Structure` instance.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `tableDescription` __optional__ | __Array__\<[ColumnStructure](../typedefs/column-structure)\> | An array holding a list of column structure objects to define columns with.<br/><br/>You can get a `tableDescription` from a structure with the [get()](#get) method, store it and load it again by creating a [Structure](#structure) with it in this constructor. |
| `tableDescription` __optional__ | __Array__\<[ColumnStructure](../typedefs/column-structure)\> | A list of column structure objects defining table columns.<br/><br/>A table description can be retrieved using the [get()](#get) method and later reloaded by passing it to the `Structure` constructor. |
**Returns**
&rarr; `this`
&rarr; `this` - The instance of `Structure`.
***
### get()
&rarr; () &rarr; __Array__\<[ColumnStructure](../typedefs/column-structure)\>
Returns an array containing all defined columns in the [ColumnStructure](../typedefs/column-structure) object.
With this you can save the structure and load it again by passing it to the [constructor](#constructor) of a new [Structure](#structure).
Retrieves an array of all defined columns in the `Structure` as [ColumnStructure](../typedefs/column-structure) objects.
**Returns**
&rarr; __Array__\<[ColumnStructure](../typedefs/column-structure)\>
&rarr; __Array__\<[ColumnStructure](../typedefs/column-structure)\> - A list of defined columns.
***
### drop()
&rarr; (`name` = __String__) &rarr; `this`
Drops (removes) a column from this structure.
Removes a column from the structure.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | The column name to drop |
| `name` | __String__ | The column name to remove. |
**Returns**
@ -53,527 +57,76 @@ Drops (removes) a column from this structure.
***
### char()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
## Column Methods
Adds a new column of data type 'char' to this structure
Each of these methods adds a column of the specified type to the structure.
**Parameters**
---
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of characters to store in this column. <br/><br/>- _Min_: 0<br/>- _Max_: 255<br/>- _Default_: 1 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
### String-Based Columns
**Returns**
| Method | Parameters | Description |
| -- | -- | -- |
| char(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*0-255, default 1*) | Adds a fixed-length character column. |
| varchar(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*0-255, default 1*) | Adds a variable-length character column. |
| tinytext(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `tinytext` column. |
| text(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `text` column. |
| mediumtext(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `mediumtext` column. |
| longtext(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `longtext` column. |
&rarr; `this`
---
***
### Binary Data Columns
### varchar()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
| Method | Parameters | Description |
| -- | -- | -- |
| binary(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1+, default 1*) | Adds a binary column. |
| varbinary(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*0+, default 1*) | Adds a variable-length binary column. |
| tinyblob(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `tinyblob` column. |
| blob(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*0-65535, default 65535*) | Adds a `blob` column. |
| longblobl(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `longblob` column. |
Adds a new column of data type 'varchar' to this structure
---
**Parameters**
| Method | Parameters | Description |
| -- | -- | -- |
| enum(`name`: __String__, `vals`: __Array__\<__String__\>, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `vals`: *Array of allowed values* | Adds an `enum` column with predefined values. |
| set(`name`: __String__, `vals`: __Array__\<__String__\>, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `vals`: *Array of allowed values* | Adds a `set` column with multiple selectable values. |
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of characters to store in this column. <br/><br/>- _Min_: 0<br/>- _Max_: 255<br/>- _Default_: 1 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
---
**Returns**
### Numeric Columns
&rarr; `this`
| Method | Parameters | Description |
| -- | -- | -- |
| bit(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-64, default 1*) | Adds a `bit` column. |
| tinyint(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-255, default 255*) | Adds a `tinyint` column. |
| bool(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Alias for `tinyint(1)`. |
| smallint(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-255, default 255*) | Adds a `smallint` column. |
| mediumint(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-255, default 255*) | Adds a `mediumint` column. |
| int(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-255, default 255*) | Adds an `int` column. |
| bigint(`name`: __String__, `size`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1-255, default 255*) | Adds a `bigint` column. |
***
---
### binary()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
### Floating Point & Decimal Columns
Adds a new column of data type 'binary' to this structure
| Method | Parameters | Description |
| -- | -- | -- |
| float(`name`: __String__, `p`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `p`: (*1-53, default 25*) | Adds a `float` column. |
| double(`name`: __String__, `size`?: __Number__, `d`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1+, default 16*)<br/>`d`: (*1+, default 8*) | Adds a `double` dolumn. |
| decimal(`name`: __String__, `size`?: __Number__, `d`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `size`: (*1+, default 16*)<br/>`d`: (*1+, default 8*) | Adds a `decimal` column. |
**Parameters**
---
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Default_: 1 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
### Date & Time Columns
**Returns**
| Method | Parameters | Description |
| -- | -- | -- |
| date(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `date` column. |
| datetime(`name`: __String__, `fsp`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `fsp`: (*0-6, default 0*) | Adds a `datetime` column. |
| timestamp(`name`: __String__, `fsp`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `fsp`: (*0-6, default 0*) | Adds a `timestamp` column. |
| time(`name`: __String__, `fsp`?: __Number__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | `fsp`: (*0-6, default 0*) | Adds a `time` column. |
| year(`name`: __String__, `options`?: [ConstraintOptions](../typedefs/constraint-options)) | - | Adds a `year` column. |
&rarr; `this`
***
### varbinary()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'varbinary' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 0<br/>- _Default_: 1 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### tinyblob()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'tinyblob' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### tinytext()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'tinytext' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### text()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'text' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### blob()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'blob' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of characters to store in this column. <br/><br/>- _Min_: 0<br/>- _Max_: 65535<br/>- _Default_: 65535 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### mediumtext()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'mediumtext' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### longtext()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'longtext' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### longblob()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'longblob' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### enum()
&rarr; (`name` = __String__, `vals`? = __Array__\<__String__\>, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'enum' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `vals` | __Array__\<__String__\> | Array of possible values for this column. |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### set()
&rarr; (`name` = __String__, `vals`? = __Array__\<__String__\>, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'enum' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `vals` | __Array__\<__String__\> | Array of possible values for this column. |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### bit()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'bit' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 64<br/>- _Default_: 1 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### tinyint()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'tinyint' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 255<br/>- _Default_: 255 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### bool()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'bool' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### smallint()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'smallint' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 255<br/>- _Default_: 255 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### mediumint()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'mediumint' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 255<br/>- _Default_: 255 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### int()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'int' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 255<br/>- _Default_: 255 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### bigint()
&rarr; (`name` = __String__, `size`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'bigint' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Max_: 255<br/>- _Default_: 255 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### float()
&rarr; (`name` = __String__, `p`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'float' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `p` __optional__ | __Number__ | Precision. <br/><br/>- _Min_: 1<br/>- _Max_: 53<br/>- _Default_: 25 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### double()
&rarr; (`name` = __String__, `size`? = __Number__, `d`? = __Number__ `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'double' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Default_: 16 |
| `d` __optional__ | __Number__ | Double precision. <br/><br/>- _Min_: 1<br/>- _Default_: 8 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### decimal()
&rarr; (`name` = __String__, `size`? = __Number__, `d`? = __Number__ `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'decimal' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `size` __optional__ | __Number__ | Maximum length of data. <br/><br/>- _Min_: 1<br/>- _Default_: 16 |
| `d` __optional__ | __Number__ | Double precision. <br/><br/>- _Min_: 1<br/>- _Default_: 8 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### date()
&rarr; (`name` = __String__,`options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'date' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### datetime()
&rarr; (`name` = __String__, `fsp`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'datetime' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `fsp` __optional__ | __Number__ | Fractional second precision. <br/><br/>- _Min_: 0<br/>- _Max_: 6<br/>- _Default_: 0 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### timestamp()
&rarr; (`name` = __String__, `fsp`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'timestamp' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `fsp` __optional__ | __Number__ | Fractional second precision. <br/><br/>- _Min_: 0<br/>- _Max_: 6<br/>- _Default_: 0 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### time()
&rarr; (`name` = __String__, `fsp`? = __Number__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'time' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `fsp` __optional__ | __Number__ | Fractional second precision. <br/><br/>- _Min_: 0<br/>- _Max_: 6<br/>- _Default_: 0 |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
### year()
&rarr; (`name` = __String__, `options`? = [ConstraintOptions](../typedefs/constraint-options)) &rarr; `this`
Adds a new column of data type 'year' to this structure
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `name` | __String__ | Name of the column |
| `options` __optional__ | [ConstraintOptions](../typedefs/constraint-options) | Additional constraint options |
**Returns**
&rarr; `this`
***
---

View File

@ -4,26 +4,30 @@ sidebar_position: 6
# Update
Performs a query to update data in a table.
Executes a query to update data in a table.
:::warning Possible crash
To prevent accidental update of all rows, this will throw an error on [execute()](#execute) if no [where()](#where) was defined.
:::warning Possible Crash
To prevent accidental updates on all rows, this operation will **throw an error** when calling [execute()](#execute) if no [where()](#where) clause is defined.
To enable the update of all rows use [force()](#force).
To explicitly allow updates on all rows, use [force()](#force).
:::
---
## Methods
---
### data()
&rarr; (`object` = __Object__) &rarr; `this`
Updates all matching rows with the given object.
Updates all matching rows with the provided data.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `object` | __Object__ | The object with the data to update to. Keys represent column names. |
| `object` | __Object__ | An object where keys represent column names and values represent the new data. |
**Returns**
@ -34,13 +38,13 @@ Updates all matching rows with the given object.
### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`
Selects a different database for this query.
Selects a different database for the query.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |
| `database` | __String__ | The name of the database to use for the update. |
**Returns**
@ -51,7 +55,7 @@ Selects a different database for this query.
### force()
&rarr; () &rarr; `this`
Enables update of all rows.
Allows updates on **all rows** in the table.
**Returns**
@ -62,17 +66,15 @@ Enables update of all rows.
### where()
&rarr; (`string` = __String__, `values` = __Array__\<__any__\>) &rarr; `this`
Adds a where-clause to the query
- Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
- If you are using joins, specify the table and column together: table.column
Adds a `WHERE` clause to filter the update query.
- Use `?` as placeholders in the condition string to prevent SQL injection.
**Parameters**
| Parameter | Type | Description |
| -- | -- | -- |
| `string` | __String__ | The where-clause as a string with ? representing each values. |
| `values` | __Array__\<__any__\> | Array containing values replacing the ? in the string (from left to right) |
| `string` | __String__ | The `WHERE` clause with `?` placeholders. |
| `values` | __Array__\<__any__\> | An arrray of values replacing the placeholders in *left-to-right* order. |
**Returns**
@ -83,7 +85,7 @@ Adds a where-clause to the query
### execute()
`async` &rarr; () &rarr; [OkPacket](../typedefs/okpacket)
Executes the prepared query.
Executes the prepared update query.
**Returns**

View File

@ -5,39 +5,35 @@ slug: /
# Introduction
:::warning Documentation not finished
This documentation is still in development.
*awSQL* is a fast and reliable database query tool designed to:
- ✅ Minimize the risk of SQL injections
- ✅ Maximize usability and safety
- ✅ Prevent accidental bulk row modifications
Some examples might be missing.
:::
awSQL is a fast and reliable database query tool.
It is designed to minimize the risk of sql-injections while maximizing usability and safety.
It prevents you from altering a whole set of rows by accident.
awSQL is designed to programmatically work with databases in an obvious manner. No more writing pesky and confusing sql-queries.
With awSQL, you can programmatically interact with databases in a clear and intuitive manner - *no more writing complex SQL queries manually!*
## Getting Started
To get started all you need is:
**Requirements**
- An hosted database
- Your credentials
To begin, ensure you have:
- A *hosted database*
- Your *database credentials*
To install `awSQL` you can use npm:
**Installation**
```shell
Install `awSQL` via **npm**:
```shell showLineNumbers
npm i git+https://git.pwcca.eu/Sam/awSQL.git#release
```
- Please make sure to use the #release branch to not download the dev-version.
:::warning Important
Always use the `#release` branch to avoid downloading the development version.
:::
## Exports
awSQL exports 2 modules to use:
- [awSQL](./classes/awSQL) as an instance
- [Structure](./classes/structure)
`awSQL` provides two core modules:
- [awSQL](./classes/awSQL) - The main database instance
- [Structure](./classes/structure) - A module for defining table structures

View File

@ -4,9 +4,9 @@ sidebar_position: 2
# ColumnStructure
`Object`
**Type:** `Object`
This defines a single column object used by [Structure](../classes/structure).
Represents a single column object used by [Structure](../classes/structure).
## Example structure
@ -33,43 +33,47 @@ The column name.
### .Type
&rarr; __String__
The column type.
The column type (e.g., `VARCHAR(255)`, `INT`, `TEXT`).
***
### .Null
&rarr; __Enum__ &rarr; `YES`/`NO`
Whether the column allows null-values.
Specifies whether the column allows `NULL` values.
***
### .Key
&rarr; __Enum__ &rarr; ` `/`PRI`/`MUL`/`UNI`
Key-Values for the table.
Defines the key type for the column.
- ` `(Empty) = None
- `PRI` = Primary
- `MUL` = Indexed
- `UNI` = Unique
| Value | Meaning |
| -- | -- |
| `""` (*empty*) | No key |
| `PRI` | Primary key |
| `MUL` | Indexed (multiple rows can have the same value) |
| `UNI` | Unique (all values must be distinct) |
***
### .Default
&rarr; __String__ / __null__
Default value for a new row.
THe default value for the column (if any).
***
### .Extra
&rarr; __Enum__ &rarr; ` `/`auto_increment`
&rarr; __Enum__ &rarr; `""`/`auto_increment`
Extra values for the table.
Additional attributes for the column.
- ` `(Empty) = None
- `auto_increment` = Primary key will be incremented on new data
| Value | Meaning |
| -- | -- |
| `""` (*empty*) | No extra properties |
| `auto_increment` | The column value auto-increments (typically for primary keys) |
***

View File

@ -4,18 +4,18 @@ sidebar_position: 3
# ConstraintOptions
`Object`
**Type:** `Object`
An object used to define additional constraints for a column within a [Structure](../classes/structure).
Defines additional constraints for a column within a [Structure](../classes/structure).
:::info
All keys within this object are __optional__.
You only need to define the keys for the settings you want to enable.
Default values are always `false` on __Booleans__ or `""` on __Strings__
- **All keys in the object are optional**
- Only define the keys for the constraints you want to enable.
:::
---
## Example structure
```js
@ -30,57 +30,61 @@ Default values are always `false` on __Booleans__ or `""` on __Strings__
}
```
---
## Properties
---
### .primary
&rarr; __Boolean__
Whether this column should be the primary one.
Defines if this column should be the primary key.
***
### .index
&rarr; __Boolean__
Whether this column should be indexable (Faster query, slower insertion)
Marks the column as indexable (improves query speed but slows insertion).
***
### .null
&rarr; __Boolean__
Whether this column is null per default
Determines if the column allows `NULL` values by default.
***
### .unique
&rarr; __Boolean__
Whether this column data should be unique and block duplicate data.
Ensures that all values in this column are unique, preventing duplicates.
***
### .default
&rarr; __String__
Sets the default data for this column that gets inserted if no data was given on insertion.
The default value inserted when no value is providded.
***
### .auto_increment
&rarr; __Boolean__
Whether this column should be numerical incremented on new insertions.
Increments the column value automatically on new insertions (typically used for primary keys).
***
### .unsigned
&rarr; __Boolean__
Defines whether the column should be **unsigned** (i.e., only allow non-negative numbers).
:::danger Warning
This option is only valid on numerical columns.
This option is **only valid for numerical columns**.
:::
Whether this column should be unsigned.
***

View File

@ -12,29 +12,33 @@ The OkPacket is a response object from MySQL that provides metadata about a succ
| Property | Type | Description |
| -- | -- | -- |
| `fieldCount` | __Number__ | Defaults to 0 on non-select queries |
| `affectedRows` | __Number__ | The number of rows affected by the query. Does not mean all rows were changed |
| `insertId` | __Number__ | The ID of the last inserted row if the table has an auto-increment column; otherwise always 0 |
| `serverStatus` | __Number__ | A status flag representing the current state of the mysql server |
| `warningCount` | __Number__ | The number of warnings generated during query execution |
| `message` | __String__ | An optional message providin additional information about the query result (normally empty) |
| `protocol41` | __Boolean__ | Whether mysql protocol 4.1 or later is used |
| `changedRows` | __Number__ | The number of rows actually changed by the query |
| `fieldCount` | __Number__ | Defaults to `0` for non-`SELECT` queries. |
| `affectedRows` | __Number__ | The number of rows affected by the query (*does not necessarily mean all rows were changed*). |
| `insertId` | __Number__ | The ID of the last inserted row (*if an auto-increment column exists, otherwise `0`*). |
| `serverStatus` | __Number__ | A bitmask flag representing the current state of the MySQL server. |
| `warningCount` | __Number__ | The number of warnings generated during query execution. |
| `message` | __String__ | An optional message providing additional information about the query result (*typically empty*). |
| `protocol41` | __Boolean__ | `true` if MySQL protocol 4.1 or later is used. |
| `changedRows` | __Number__ | The number of rows actually modified by the query. |
## Common serverStatus
## Common `serverStatus` Flags
:::info `serverStatus` is a bitmask
This means multiple statuses can be set at the same time. For example, if `SERVER_STATUS_AUTOCOMMIT` (__1__) and `SERVER_STATUS_IN_TRANS` (__2__) are both active, the `serverStatus` value will be the combination of the corresponding bits (bitwise OR operation). It therefore will become __3__
:::info Bitmask Behavior
`serverStatus` is a **bitmask**, meaning multiple statuses can be active at the same time.
For example:
- `SERVER_STATUS_AUTOCOMMIT` (`1`) + `SERVER_STATUS_IN_TRANS` (`2`)
- These combine to `3` (`1` | `2` = `3`) through a **bitwise OR** operation.
:::
| `serverStatus`-Value | Status | Description |
| -- | -- | -- |
| __1__ | `SERVER_STATUS_AUTOCOMMIT` | The server is in autocommit mode, meaning each query is treated as a single transaction and is automatically committed |
| __2__ | `SERVER_STATUS_IN_TRANS` | The server is in a transaction. This means that queries are being executed within an open transaction, and they have not been committed yet |
| __8__ | `SERVER_STATUS_MORE_RESULTS_EXISTS` | There are more result set available. This status is seen when a `SELECT` query returns multiple result sets (e.g., when using `SELECT ... INTO OUTFILE`) |
| __16__ | `SERVER_STATUS_NO_GOOD_INDEX_USED` | The server did not use a good index for the query. This might indicate a suboptimal query execution, such as using a less efficient index for the query |
| __32__ | `SERVER_STATUS_NO_INDEX_USED` | The server did not use any __index__ for the query, which may lead to slower performance due to a full table scan |
| __64__ | `SERVER_STATUS_QUERY_NO_GOOD_INDEX_USED` | Indicates that no suitable index was used during the query execution, potentially resulting in performance issues |
| __128__ | `SERVER_STATUS_CURSOR_EXISTS` | A __cursor__ exists and is used for the query. This status is relevant for more complex queries or when cursors are used for querying |
| __256__ | `SERVER_STATUS_LAST_INSERT_ID` | This status indicates that the __last__ `INSERT` __statement__ generated an `AUTO_INCREMENT` ID. It is important for `INSERT` queries, as it relates to auto-generated IDs |
| __512__ | `SERVER_STATUS_DB_DROPPED` | This status indicates that a __database was dropped__ |
| __1__ | `SERVER_STATUS_AUTOCOMMIT` | The server is in **autocommit mode**, treating each query as a seperate transaction that commits automatically. |
| __2__ | `SERVER_STATUS_IN_TRANS` | The server is currently in a **transaction** (*queries have not been committed yet*). |
| __8__ | `SERVER_STATUS_MORE_RESULTS_EXISTS` | More result sets exist (*e.g., when executing a `SELECT ... INTO OUTFILE` query*). |
| __16__ | `SERVER_STATUS_NO_GOOD_INDEX_USED` | The server did not use an **optimal index** for the query, which may indicate inefficient execution. |
| __32__ | `SERVER_STATUS_NO_INDEX_USED` | The query was executed **without an index**, likely causing a full table scan (*may impact performance*). |
| __64__ | `SERVER_STATUS_QUERY_NO_GOOD_INDEX_USED` | No **suitable index** was used during query execution (*could result in performance issues*). |
| __128__ | `SERVER_STATUS_CURSOR_EXISTS` | A **cursor** exists and is in use for this query (*typically seen in more complex queries*). |
| __256__ | `SERVER_STATUS_LAST_INSERT_ID` | The **last executed `INSERT` statement** generated an `AUTO_INCREMENT` ID. |
| __512__ | `SERVER_STATUS_DB_DROPPED` | A **database was dropped** as part of the executed query. |

View File

@ -16,6 +16,7 @@ const { throwTypeError } = require("./lib/Errors");
* @property {Boolean} [insecureAuth] - Whether insecure authentication methods should be allowed
* @property {String} [customIdentifier] - Sets a custom identifier for this instance
* @property {Boolean} [isDefault] - Whether this instance is returned by default via 'getInstance'
* @property {object} [ssl] - Whether to use ssl
*/
/**
@ -40,6 +41,7 @@ class awSQL {
insecureAuth: false,
customIdentifier: false,
isDefault: false,
ssl: false,
}){
if (!password) throw new Error(`Can't create instance: No password given`);
if (!username) throw new Error(`Can't create instance: No username given`);
@ -106,9 +108,10 @@ class Instance {
#multipleStatements;
#charset;
#connection;
#ssl;
#selectedDatabase;
constructor(hostname="localhost", username, password, charset="utf8mb4", defaultDatabase=false, multipleStatements=false, insecureAuth=false){
constructor(hostname="localhost", username, password, charset="utf8mb4", defaultDatabase=false, multipleStatements=false, insecureAuth=false, ssl=false){
this.#host = hostname;
this.#user = username;
this.#password = password;
@ -116,6 +119,7 @@ class Instance {
this.#multipleStatements = multipleStatements;
this.#insecureAuth = insecureAuth;
this.#selectedDatabase = defaultDatabase||username;
this.#ssl = ssl;
}
/**
@ -130,7 +134,8 @@ class Instance {
host: this.#host,
insecureAuth: this.#insecureAuth,
multipleStatements: this.#multipleStatements,
charset: this.#charset
charset: this.#charset,
ssl: this.#ssl
});
this.#connection = connection; // Store the connection
connection.connect((err) =>{

View File

@ -1,15 +1,25 @@
{
"name": "awsql",
"version": "1.0.0",
"description": "[Documentation](https://docs.pwcca.eu/awSQL)",
"repository": {
"type": "git",
"url": "https://Sam@git.pwcca.eu/Sam/awSQL.git"
},
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"directories": {
"doc": "docs",
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.7",
"mysql": "^2.18.1"
},
"description": ""
"devDependencies": {}
}