@vinctus/oql 1.1.0-scope.1 → 1.1.0

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.
package/README.md CHANGED
@@ -8,13 +8,17 @@
8
8
  - [TypeScript/JavaScript](#typescriptjavascript)
9
9
  - [Scala.js](#scalajs)
10
10
  - [Usage](#usage)
11
- - [TypeScript](#typescript)
12
- - [Scala.js](#scalajs-1)
11
+ - [Tutorial](#tutorial)
13
12
  - [API](#api)
14
13
  - [Examples](#examples)
15
14
  - [Tests](#tests)
15
+ - [Requirements](#requirements)
16
+ - [Setup PostgreSQL](#setup-postgresql)
17
+ - [Clone the repository](#clone-the-repository)
18
+ - [Build the test database](#build-the-test-database)
19
+ - [Run tests](#run-tests)
16
20
  - [License](#license)
17
-
21
+
18
22
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
19
23
 
20
24
  OQL
@@ -64,11 +68,11 @@ Add the following lines to your `build.sbt`:
64
68
  ```sbt
65
69
  externalResolvers += "OQL" at "https://maven.pkg.github.com/vinctustech/oql"
66
70
 
67
- libraryDependencies += "com.vinctus" %%% "-vinctus-oql" % "1.0.0-RC.3.23"
71
+ libraryDependencies += "com.vinctus" %%% "-vinctus-oql" % "1.1.0"
68
72
 
69
73
  Compile / npmDependencies ++= Seq(
70
- "pg" -> "8.5.1",
71
- "@types/pg" -> "7.14.7"
74
+ "pg" -> "8.10.0",
75
+ "@types/pg" -> "8.6.6"
72
76
  )
73
77
  ```
74
78
 
@@ -111,9 +115,75 @@ Several examples are given [here](https://vinctustech.github.io/oql/examples.htm
111
115
  Tests
112
116
  -----
113
117
 
114
- in progress: ticket #OQL-24
118
+ ### Requirements
119
+
120
+ - Git (for cloning)
121
+ - Java 11+
122
+ - [sbt](https://www.scala-sbt.org/1.x/docs/Setup.html) (for building and running tests)
123
+
124
+ ### Setup PostgreSQL
125
+
126
+ To run the unit test, you will need to get [PostgreSQL](https://hub.docker.com/_/postgres) running in a [docker container](https://www.docker.com/resources/what-container):
127
+
128
+ ```
129
+ docker pull postgres
130
+ docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 postgres
131
+ ```
132
+
133
+ The [PostgreSQL client](https://www.postgresql.org/docs/13.3/app-psql.html) (`psql`) should be installed. If necessary, it can be installed with the command
134
+
135
+ `sudo apt-get install postgresql-client`
136
+
137
+ ### Clone the repository
138
+
139
+ At the shell terminal go to the folder where the sources will be downloaded, referred to as `dev-path/`, and type
140
+
141
+ ```
142
+ git git@github.com:vinctustech/oql.git
143
+ ```
144
+
145
+ This will create folder `dev-path/oql`.
146
+
147
+ ### Build the test database
148
+
149
+ Type
150
+
151
+ ```shell
152
+ cd oql/test
153
+
154
+ sh start
155
+
156
+ sh tests
157
+
158
+ sh build
159
+ ```
160
+
161
+ The last few lines of output should be
162
+
163
+ ```
164
+ CREATE TABLE
165
+ ALTER TABLE
166
+ INSERT 0 4
167
+ INSERT 0 4
168
+ ```
169
+
170
+ ### Run tests
171
+
172
+ Type
173
+
174
+ ```
175
+ cd ..
176
+ sbt test
177
+ ```
178
+
179
+ You should see
180
+
181
+ ```
182
+ [info] All tests passed.
183
+ ```
115
184
 
116
185
  License
117
186
  -------
118
187
 
119
188
  OQL uses the commercial friendly open source [ISC](https://raw.githubusercontent.com/vinctustech/oql/stable/LICENSE) license.
189
+
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export class QueryBuilder {
1
+ export class QueryBuilder<T = any> {
2
2
 
3
- cond(v: any): QueryBuilder
3
+ cond(v: any): QueryBuilder<T>
4
4
 
5
5
  // add(attribute: QueryBuilder): QueryBuilder
6
6
  //
@@ -8,19 +8,19 @@ export class QueryBuilder {
8
8
  //
9
9
  // project(resource: string, ...attributes: string[]): QueryBuilder
10
10
 
11
- query(oql: string, parameters?: any): QueryBuilder
11
+ query(oql: string, parameters?: any): QueryBuilder<T>
12
12
 
13
- select(oql: string, parameters?: any): QueryBuilder
13
+ select(oql: string, parameters?: any): QueryBuilder<T>
14
14
 
15
- order(attribute: string, sorting: string): QueryBuilder
15
+ order(attribute: string, sorting: string): QueryBuilder<T>
16
16
 
17
- limit(a: number): QueryBuilder
17
+ limit(a: number): QueryBuilder<T>
18
18
 
19
- offset(a: number): QueryBuilder
19
+ offset(a: number): QueryBuilder<T>
20
20
 
21
- getOne(): Promise<any | undefined>
21
+ getOne(): Promise<T | undefined>
22
22
 
23
- getMany(): Promise<any[]>
23
+ getMany(): Promise<T[]>
24
24
 
25
25
  getCount(): Promise<number>
26
26
 
@@ -28,13 +28,13 @@ export class QueryBuilder {
28
28
 
29
29
  export class Mutation {
30
30
 
31
- insert(obj: any): Promise<any>
31
+ insert<T = any>(obj: any): Promise<T>
32
32
 
33
33
  link(id1: any, resource: string, id2: any): Promise<void>
34
34
 
35
35
  unlink(id1: any, resource: string, id2: any): Promise<void>
36
36
 
37
- update(id: any, updates: any): Promise<void>
37
+ update<T = any>(id: any, updates: any): Promise<T>
38
38
 
39
39
  bulkUpdate(updates: [any, any][]): Promise<void>
40
40
 
@@ -46,18 +46,44 @@ export class OQL {
46
46
 
47
47
  constructor(dm: string, host: string, port: number, database: string, user: string, password: string, ssl: any, idleTimeoutMillis: number, max: number)
48
48
 
49
+ create(): Promise<void>
50
+
51
+ showQuery(): void
52
+
53
+ entity(name: string): Mutation
54
+
55
+ queryBuilder<T = any>(fixed?: string, at?: any): QueryBuilder<T>
56
+
57
+ queryOne<T = any>(oql: string, parameters?: any, fixed?: string, at?: any): Promise<T | undefined>
58
+
59
+ queryMany<T = any>(oql: string, parameters?: any, fixed?: string, at?: any): Promise<T[]>
60
+
61
+ count(oql: string, parameters?: any, fixed?: string, at?: any): Promise<number>
62
+
63
+ raw(sql: string, values?: any[]): Promise<any[][]>
64
+
65
+ }
66
+
67
+ export class OQL_MEM {
68
+
69
+ constructor(dm: string)
70
+
71
+ create(): Promise<void>
72
+
49
73
  showQuery(): void
50
74
 
51
75
  entity(name: string): Mutation
52
76
 
53
- queryBuilder(): QueryBuilder
77
+ queryBuilder<T = any>(fixed?: string, at?: any): QueryBuilder<T>
78
+
79
+ queryOne<T = any>(oql: string, parameters?: any, fixed?: string, at?: any): Promise<T | undefined>
54
80
 
55
- queryOne(oql: string, parameters?: any): Promise<any | undefined>
81
+ queryMany<T = any>(oql: string, parameters?: any, fixed?: string, at?: any): Promise<T[]>
56
82
 
57
- queryMany(oql: string, parameters?: any, fixed?: string, at?: any): Promise<any[]>
83
+ count(oql: string, parameters?: any, fixed?: string, at?: any): Promise<number>
58
84
 
59
- count(oql: string, parameters?: any): Promise<number>
85
+ raw(sql: string, values?: any[]): Promise<any[][]>
60
86
 
61
- raw(sql: string, values?: any[]): Promise<any[]>
87
+ rawMulti(sql: string): Promise<void>
62
88
 
63
89
  }