Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #330 from Uconnect-Technologies/dev-ilyas/mysql-enum
Browse files Browse the repository at this point in the history
Dev ilyas/mysql enum
  • Loading branch information
ilyaskarim authored Jan 25, 2022
2 parents 1282cd4 + 585a635 commit 8902f19
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 147 deletions.
6 changes: 3 additions & 3 deletions docs/v1/custom-modules/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let configuration = {
modules: [
{
name: "Article",
useDatabase: true,
useMysqlDatabase: true,
fields: {
sql: {
title: {
Expand Down Expand Up @@ -81,7 +81,7 @@ To allow database you have to configure your module in this way:
let configuration = {
modules: [
{
useDatabase: true, // Set false if you are not storing data for this module.
useMysqlDatabase: true, // Set false if you are not storing data for this module.
database: {
sql: {
tableName: "YOUR_TABLE_NAME",
Expand Down Expand Up @@ -170,7 +170,7 @@ The above module will generate these GraphQL subscriptions:

#### Rest API:

So when you enable useDatabase feature, If you have enabled RestAPI these API's will be generated by Wertik for the module named Person:
So when you enable useMysqlDatabase feature, If you have enabled RestAPI these API's will be generated by Wertik for the module named Person:

[SAVE] http://localhost:7000/api/v1/person/save - {input: args }
[POST] http://localhost:7000/api/v1/person/create - {input: args }
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/custom-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ With this guide, you can extend your app with extra modules and functionality. P
**Default Value:** null
**Description:** The name of module.

### useDatabase
### useMysqlDatabase

**Type:** Boolean
**Default Value:** true
Expand Down
6 changes: 3 additions & 3 deletions docs/v3/database.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Database

As of today 28 November 2021, Wertik-js only supports MySQL database. Wertik JS provides a function called `useDatabase` you can use to connect to a database.
As of today 28 November 2021, Wertik-js only supports MySQL database. Wertik JS provides a function called `useMysqlDatabase` you can use to connect to a database.

```js
import wertik, { useDatabase } from "wertik-js/lib/next";
import wertik, { useMysqlDatabase } from "wertik-js/lib/next";
weritk({
port: 1200,
database: {
default: useDatabase({
default: useMysqlDatabase({
name: "default",
password: "pass",
host: "localhost",
Expand Down
4 changes: 2 additions & 2 deletions docs/v3/mailer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
To send emails. Wertik-js uses Node Mailer for sending emails. To setup emails Wertik JS provides a function called `useMailer` as argument you need to pass Node Mailer Configuration.

```js
import wertik, { useDatabase, useMailer } from "wertik-js/lib/next";
import wertik, { useMysqlDatabase, useMailer } from "wertik-js/lib/next";
weritk({
port: 1200,
database: {
default: useDatabase({
default: useMysqlDatabase({
name: "default",
password: "pass",
host: "localhost",
Expand Down
25 changes: 13 additions & 12 deletions docs/v3/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Wertik-js allows extending your app with more features using the `modules` term.

```js
import wertik, {
useDatabase,
useMysqlDatabase,
useMailer,
useModule,
useGraphql,
Expand All @@ -13,7 +13,7 @@ import wertik, {
weritk({
port: 1200,
database: {
default: useDatabase({
default: useMysqlDatabase({
name: "default",
password: "pass",
host: "localhost",
Expand All @@ -30,7 +30,7 @@ weritk({
table: "users",
database: "default",
name: "users",
useDatabase: true,
useMysqlDatabase: true,
}),
},
});
Expand All @@ -40,20 +40,20 @@ Please check this [interface](https://github.com/Uconnect-Technologies/wertik-js

# Modules GraphQL Schema and Database operations

When you provide `useDatabase: true`, `table` and `database`, Wertik JS automatically generates GraphQL schema, `updateInput` and `createInput`. For example let's say you have a table called `Games` with following fields:
When you provide `useMysqlDatabase: true`, `table` and `database`, Wertik JS automatically generates GraphQL schema, `updateInput` and `createInput`. For example let's say you have a table called `Games` with following fields:

- name: varchar
- publisher: varchar

You have to initialize its module in this way:

```js
import wertik, { useModule, useDatabase, useGraphql } from "wertik-js/lib/next";
import wertik, { useModule, useMysqlDatabase, useGraphql } from "wertik-js/lib/next";
wertik({
port: 1200,
graphql: useGraphql(),
database: {
default: useDatabase({
default: useMysqlDatabase({
name: "dbname",
password: "pass",
host: "localhost",
Expand All @@ -63,7 +63,7 @@ wertik({
},
modules: {
games: useModule({
useDatabase: true,
useMysqlDatabase: true,
name: "Games",
table: "games",
database: "default",
Expand Down Expand Up @@ -127,6 +127,7 @@ type Query {
}
```

**Note:** When you are using enums in table please make sure that your enum value doesn't contains dashes, it should be something like this `enum('X_SMALL','X_LARGE')` not `enum('X-SMALL','X-LARGE')`.
### Mutations:

- update
Expand All @@ -151,7 +152,7 @@ You can try these `Mutations` and `Queries` in your GraphQL playground. If you f

# More on filtering rows from a table

When you provide `useDatabase: true` for a module called Games. Wertik JS will create a query as:
When you provide `useMysqlDatabase: true` for a module called Games. Wertik JS will create a query as:

```graphql
listGames(
Expand Down Expand Up @@ -218,12 +219,12 @@ When events are running you get access to Apollo GraphQL Resolver arguments wher
Example:

```js
import wertik, { useDatabase, useModule } from "wertik-js/lib/next";
import wertik, { useMysqlDatabase, useModule } from "wertik-js/lib/next";

wertik({
port: 1200,
database: {
default: useDatabase({
default: useMysqlDatabase({
name: "default",
password: "pass",
host: "localhost",
Expand All @@ -233,7 +234,7 @@ wertik({
},
modules: {
games: useModule({
useDatabase: true,
useMysqlDatabase: true,
name: "Games",
table: "games",
database: "jscontainer",
Expand Down Expand Up @@ -275,7 +276,7 @@ wertik({
port: 1200,
modules: {
games: useModule({
useDatabase: true,
useMysqlDatabase: true,
name: "Games",
table: "games",
database: "jscontainer",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wertik-js",
"version": "3.1.5",
"version": "3.1.6",
"main": "lib/main.js",
"types": "lib/types.d.ts",
"repository": "https://github.com/Uconnect-Technologies/wertik-js.git",
Expand Down
7 changes: 6 additions & 1 deletion src/next/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getAllRelationships = (dbName: String) => {
`
}

export const useDatabase = function (obj: useDatabaseProps) {
export const useMysqlDatabase = function (obj: useDatabaseProps) {
return async () => {
let sequelize = new Sequelize(obj.name, obj.username, obj.password, {
host: obj.host,
Expand All @@ -40,6 +40,11 @@ export const useDatabase = function (obj: useDatabaseProps) {
}
}

/**
* @deprecated use useMysqlDatabase instead useDatabase is deprecated and will be removed in 3.5.0 version.
*/
export const useDatabase = useMysqlDatabase

export const applyRelationshipsFromStoreToDatabase = async (
store: Store,
app: WertikApp
Expand Down
38 changes: 26 additions & 12 deletions src/next/devServers/dev-ilyas.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import wertik from "../index"
import { useQueue } from "../queue"
import { useMysqlDatabase } from "../database"
import { useGraphql } from "../graphql"
import wertik, { useModule } from "../index"

const devIlyas = async () => {
wertik({
port: 1200,
queue: {
options: {
useBullBoard: true,
uiPath: "/admin/jobs",
},
jobs: {
fetchGames: useQueue({
name: "fetchGames",
}),
},
graphql: useGraphql(),
database: {
default: useMysqlDatabase({
port: 3306,
username: "root",
password: "pass",
name: "wertik",
host: "localhost",
}),
},
modules: {
forgetPassword: useModule({
name: "forgetPassword",
useDatabase: true,
database: "default",
table: "forgetPassword",
}),
shirts: useModule({
name: "shirts",
useDatabase: true,
database: "default",
table: "shirts",
}),
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Wertik: (configuration: WertikConfiguration) => Promise<WertikApp> = (
redis: {},
}

const port = get(configuration, "port", 5050)
const port = get(configuration, "port", 1200)
const skip = get(configuration, "skip", false)
const expressApp = get(configuration, "express", express())
const httpServer = http.createServer(expressApp)
Expand Down
Loading

0 comments on commit 8902f19

Please sign in to comment.