Skip to content

Commit

Permalink
Merge pull request #1 from typeorm/master
Browse files Browse the repository at this point in the history
merge from typeorm
  • Loading branch information
abingoal committed Jan 10, 2019
2 parents 7d95c1a + 3bd211c commit 246100a
Show file tree
Hide file tree
Showing 18 changed files with 467 additions and 70 deletions.
49 changes: 49 additions & 0 deletions docs/find-options.md
Expand Up @@ -46,6 +46,23 @@ Querying a column from an embedded entity should be done with respect to the hie
userRepository.find({ where: { name: { first: "Timber", last: "Saw" } } });
```

Querying with OR operator:

```typescript
userRepository.find({
where: [
{ firstName: "Timber", lastName: "Saw" },
{ firstName: "Stan", lastName: "Lee" }
]
});
```

will execute following query:

```sql
SELECT * FROM "user" WHERE ("firstName" = 'Timber' AND "lastName" = 'Saw') OR ("firstName" = 'Stan' AND "lastName" = 'Lee')
```

* `order` - selection order.

```typescript
Expand Down Expand Up @@ -154,6 +171,22 @@ will execute following query:
SELECT * FROM "post" WHERE "likes" < 10
```

* `LessThanOrEqual`

```ts
import {LessThanOrEqual} from "typeorm";

const loadedPosts = await connection.getRepository(Post).find({
likes: LessThanOrEqual(10)
});
```

will execute following query:

```sql
SELECT * FROM "post" WHERE "likes" <= 10
```

* `MoreThan`

```ts
Expand All @@ -170,6 +203,22 @@ will execute following query:
SELECT * FROM "post" WHERE "likes" > 10
```

* `MoreThanOrEqual`

```ts
import {MoreThanOrEqual} from "typeorm";

const loadedPosts = await connection.getRepository(Post).find({
likes: MoreThanOrEqual(10)
});
```

will execute following query:

```sql
SELECT * FROM "post" WHERE "likes" >= 10
```

* `Equal`

```ts
Expand Down
4 changes: 3 additions & 1 deletion src/cache/QueryResultCacheFactory.ts
Expand Up @@ -32,8 +32,10 @@ export class QueryResultCacheFactory {
if ((this.connection.options.cache as any).type === "ioredis")
return new RedisQueryResultCache(this.connection, "ioredis");

if ((this.connection.options.cache as any).type === "ioredis/cluster")
return new RedisQueryResultCache(this.connection, "ioredis/cluster");

return new DbQueryResultCache(this.connection);
}


}
11 changes: 9 additions & 2 deletions src/cache/RedisQueryResultCache.ts
Expand Up @@ -26,13 +26,13 @@ export class RedisQueryResultCache implements QueryResultCache {
/**
* Type of the Redis Client (redis or ioredis).
*/
protected clientType: "redis" | "ioredis";
protected clientType: "redis" | "ioredis" | "ioredis/cluster";

// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------

constructor(protected connection: Connection, clientType: "redis" | "ioredis") {
constructor(protected connection: Connection, clientType: "redis" | "ioredis" | "ioredis/cluster") {
this.clientType = clientType;
this.redis = this.loadRedis();
}
Expand Down Expand Up @@ -61,6 +61,13 @@ export class RedisQueryResultCache implements QueryResultCache {
this.client = new this.redis();
}

} else if (this.clientType === "ioredis/cluster") {
if (cacheOptions && cacheOptions.options) {
this.client = new this.redis.Cluster(cacheOptions.options);
} else {
throw new Error(`Options required for ${this.clientType}.`);
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/connection/BaseConnectionOptions.ts
Expand Up @@ -114,7 +114,7 @@ export interface BaseConnectionOptions {
* - "database" means cached values will be stored in the separate table in database. This is default value.
* - "redis" means cached values will be stored inside redis. You must provide redis connection options.
*/
readonly type?: "database"|"redis"; // todo: add mongodb and other cache providers as well in the future
readonly type?: "database" | "redis" | "ioredis" | "ioredis/cluster"; // todo: add mongodb and other cache providers as well in the future

/**
* Used to provide redis connection options.
Expand Down
2 changes: 1 addition & 1 deletion src/connection/Connection.ts
Expand Up @@ -355,7 +355,7 @@ export class Connection {
* Wraps given function execution (and all operations made there) into a transaction.
* All database operations must be executed using provided entity manager.
*/
async transaction(runInTransaction: (entityManager: EntityManager) => Promise<any>): Promise<any> {
async transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T> {
return this.manager.transaction(runInTransaction);
}

Expand Down
79 changes: 73 additions & 6 deletions src/driver/mongodb/MongoConnectionOptions.ts
Expand Up @@ -3,6 +3,7 @@ import {ReadPreference} from "./typings";

/**
* MongoDB specific connection options.
* Synced with http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html
*/
export interface MongoConnectionOptions extends BaseConnectionOptions {

Expand Down Expand Up @@ -73,14 +74,20 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
* String or buffer containing the certificate private key we wish to present
* (needs to have a mongod server with ssl support, 2.4 or higher)
*/
readonly sslKey?: string|Buffer;
readonly sslKey?: string;

/**
* String or buffer containing the certificate password
* (needs to have a mongod server with ssl support, 2.4 or higher)
*/
readonly sslPass?: string|Buffer;

/**
* SSL Certificate revocation list binary buffer
* (needs to have a mongod server with ssl support, 2.4 or higher)
*/
readonly sslCRL?: string|Buffer;

/**
* Reconnect on error. Default: true
*/
Expand All @@ -101,6 +108,12 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
*/
readonly connectTimeoutMS?: number;

/**
* Version of IP stack. Can be 4, 6.
* If undefined, will attempt to connect with IPv6, and will fall back to IPv4 on failure
*/
readonly family?: number;

/**
* TCP Socket timeout setting. Default: 360000
*/
Expand All @@ -117,12 +130,12 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
readonly reconnectInterval?: number;

/**
* Turn on high availability monitoring. Default true
* Control if high availability monitoring runs for Replicaset or Mongos proxies. Default true
*/
readonly ha?: boolean;

/**
* Time between each replicaset status check. Default: 10000,5000
* The High availability period for replicaset inquiry. Default: 10000
*/
readonly haInterval?: number;

Expand Down Expand Up @@ -212,13 +225,13 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
* Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection,
* default is -1 which is unlimited.
*/
readonly bufferMaxEntries?: boolean;
readonly bufferMaxEntries?: number;

/**
* The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY,
* ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
*/
readonly readPreference?: ReadPreference;
readonly readPreference?: ReadPreference|string;

/**
* A primary key factory object for generation of custom _id keys.
Expand All @@ -245,13 +258,67 @@ export interface MongoConnectionOptions extends BaseConnectionOptions {
*/
readonly loggerLevel?: "error"|"warn"|"info"|"debug";

// Do not overwrite BaseConnectionOptions.logger
// readonly logger?: any;

/**
* Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function
* Default: true
*/
readonly checkServerIdentity?: boolean|Function;

/**
* Validate MongoClient passed in options for correctness. Default: false
*/
readonly validateOptions?: boolean|any;

/**
* The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections
*/
readonly appname?: string;

/**
* Sets the authentication mechanism that MongoDB will use to authenticate the connection
*/
readonly authMechanism?: string;

/**
* Specify new url parser usage
* Type of compression to use: snappy or zlib
*/
readonly compression?: any;

/**
* Specify a file sync write concern. Default: false
*/
readonly fsync?: boolean;

/**
* Read preference tags
*/
readonly readPreferenceTags?: any[];

/**
* The number of retries for a tailable cursor. Default: 5
*/
readonly numberOfRetries?: number;

/**
* Enable auto reconnecting for single server instances. Default: true
*/
readonly auto_reconnect?: boolean;

/**
* Enable command monitoring for this client. Default: false
*/
readonly monitorCommands?: boolean;

/**
* If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections
*/
readonly minSize?: number;

/**
* Determines whether or not to use the new url parser. Default: false
*/
readonly useNewUrlParser?: boolean;
}

0 comments on commit 246100a

Please sign in to comment.