Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/repository-typeorm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tgz
dist*
package
1 change: 1 addition & 0 deletions packages/repository-typeorm/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
61 changes: 61 additions & 0 deletions packages/repository-typeorm/COMPARISON.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Feature comparison between LoopBack and TypeORM

## Major features

| Feature | TypeORM | LoopBack |
| ----------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Databases | MySQL<br>PostgreSQL<br>MariaDB<br>SQLite<br>MS SQL Server<br>MongoDB<br>Oracle<br>WebSQL | In-memory<br>MySQL<br>PostgreSQL<br>SQLite<br>MS SQL Server<br>Oracle<br>MongoDB<br>Cloudant<br>CouchDB<br>DB2<br>DB2 Z<br>DB2 iSeries<br>DashDB<br>Informix<br>Cassandra<br>Key Value (...)<br><hr>ElasticSearch<br>https://github.com/pasindud/awesome-loopback<br>https://www.npmjs.com/search?q=loopback-connector (189 hits) |
| Model Definition | TypeScript classes with decorators | JSON<br>TypeScript classes with decorators |
| Data access patterns | ActiveRecord (BaseEntity)<br>EntityManager<br>Repository | ActiveRecord (3.x Model)<br>Repository (4.x) |
| Database Adapters | QueryRunner (monorepo) | Connector (multiple repos/modules) |
| Query | QueryBuilder | Filter JSON Object<br>FilterBuilder (4.x) |
| Scopes | No | Yes |
| Mutation | QueryBuilder | Where JSON Object |
| Feedback from mutations | No | Yes |
| Mixins | No | Yes |
| Transaction | Yes | Yes |
| Optimistic Locking | Yes | No (requested by AppConnect team) |
| Connection pooling | Yes | Yes |
| Relations | Yes | Yes |
| Relational Join | Yes | No |
| Discovery | No | Yes |
| Migration | Yes | Yes |

## Side by side claims by TypeORM

| Claimed by TypeORM | LoopBack |
| ---------------------------------------------------------------- | -------------------------------------------------------------------- |
| supports both DataMapper and ActiveRecord (your choice) | DataMapper is supported by Repository and ActiveRecord by 3.x models |
| entities and columns | Yes |
| database-specific column types | Yes |
| entity manager | Connectors |
| repositories and custom repositories | Yes |
| clean object relational model | Yes |
| associations (relations) | Yes |
| eager and lazy relations | Yes |
| uni-directional, bi-directional and self-referenced relations | Yes |
| supports multiple inheritance patterns | Polymorphic relations |
| cascades | No |
| indices | Yes |
| transactions | Yes |
| migrations and automatic migrations generation | Yes |
| connection pooling | Yes |
| replication | Depending on the driver |
| using multiple database connections | Yes |
| working with multiple databases types | Yes |
| cross-database and cross-schema queries | Yes |
| elegant-syntax, flexible and powerful QueryBuilder | Poc in 4 |
| left and inner joins | No |
| proper pagination for queries using joins | No |
| query caching | No |
| streaming raw results | No |
| logging | Yes - debug |
| listeners and subscribers (hooks) | Yes |
| supports closure table pattern | No |
| schema declaration in models or separate configuration files | Yes |
| connection configuration in json / xml / yml / env formats | Yes |
| works in NodeJS / Browser / Ionic / Cordova / Electron platforms | NodeJS only, 3.x is compatible with Browser |
| TypeScript and JavaScript support | Yes |
| produced code is performant, flexible, clean and maintainable | ? |
| follows all possible best practices | ? |
| CLI | Yes |
25 changes: 25 additions & 0 deletions packages/repository-typeorm/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2017. All Rights Reserved.
Node module: @loopback/repository
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
16 changes: 16 additions & 0 deletions packages/repository-typeorm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @loopback/repository-typeorm

Repository integration with TypeORM

## Tests

run 'npm test' from the root folder.

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
8 changes: 8 additions & 0 deletions packages/repository-typeorm/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"content": ["./index.ts", "./src/**/*.ts"],
"codeSectionDepth": 4,
"assets": {
"/": "/docs",
"/docs": "/docs"
}
}
6 changes: 6 additions & 0 deletions packages/repository-typeorm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2017. All Rights Reserved.
// Node module: @loopback/repository
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

export * from './dist/src';
9 changes: 9 additions & 0 deletions packages/repository-typeorm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright IBM Corp. 2017. All Rights Reserved.
// Node module: @loopback/repository
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

const nodeMajorVersion = +process.versions.node.split('.')[0];
module.exports = nodeMajorVersion >= 7 ?
require('./dist/src') :
require('./dist6/src');
7 changes: 7 additions & 0 deletions packages/repository-typeorm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright IBM Corp. 2013,2017. All Rights Reserved.
// Node module: @loopback/repository
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// NOTE(bajtos) This file is used by VSCode/TypeScriptServer at dev time only
export * from './src';
122 changes: 122 additions & 0 deletions packages/repository-typeorm/mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash

### Shell script to spin up a docker container for mysql.

## color codes
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
CYAN='\033[1;36m'
PLAIN='\033[0m'

## variables
MYSQL_CONTAINER="mysql_c"
HOST="localhost"
USER="root"
PASSWORD="pass"
PORT=3306
DATABASE="testdb"
if [ "$1" ]; then
HOST=$1
fi
if [ "$2" ]; then
PORT=$2
fi
if [ "$3" ]; then
USER=$3
fi
if [ "$4" ]; then
PASSWORD=$4
fi
if [ "$5" ]; then
DATABASE=$5
fi

## check if docker exists
printf "\n${RED}>> Checking for docker${PLAIN} ${GREEN}...${PLAIN}"
docker -v > /dev/null 2>&1
DOCKER_EXISTS=$?
if [ "$DOCKER_EXISTS" -ne 0 ]; then
printf "\n\n${CYAN}Status: ${PLAIN}${RED}Docker not found. Terminating setup.${PLAIN}\n\n"
exit 1
fi
printf "\n${CYAN}Found docker. Moving on with the setup.${PLAIN}\n"


## cleaning up previous builds
printf "\n${RED}>> Finding old builds and cleaning up${PLAIN} ${GREEN}...${PLAIN}"
docker rm -f $MYSQL_CONTAINER > /dev/null 2>&1
printf "\n${CYAN}Clean up complete.${PLAIN}\n"

## pull latest mysql image
printf "\n${RED}>> Pulling latest mysql image${PLAIN} ${GREEN}...${PLAIN}"
docker pull mysql:latest > /dev/null 2>&1
printf "\n${CYAN}Image successfully built.${PLAIN}\n"

## run the mysql container
printf "\n${RED}>> Starting the mysql container${PLAIN} ${GREEN}...${PLAIN}"
CONTAINER_STATUS=$(docker run --name $MYSQL_CONTAINER -e MYSQL_ROOT_USER=$USER -e MYSQL_ROOT_PASSWORD=$PASSWORD -p $PORT:3306 -d mysql:latest 2>&1)
if [[ "$CONTAINER_STATUS" == *"Error"* ]]; then
printf "\n\n${CYAN}Status: ${PLAIN}${RED}Error starting container. Terminating setup.${PLAIN}\n\n"
exit 1
fi
docker cp ./test/schema.sql $MYSQL_CONTAINER:/home/ > /dev/null 2>&1
printf "\n${CYAN}Container is up and running.${PLAIN}\n"

## export the schema to the mysql database
printf "\n${RED}>> Exporting default schema${PLAIN} ${GREEN}...${PLAIN}\n"

## command to export schema
docker exec -it $MYSQL_CONTAINER /bin/sh -c "mysql -u$USER -p$PASSWORD < /home/schema.sql" > /dev/null 2>&1

## variables needed to health check export schema
OUTPUT=$?
TIMEOUT=120
TIME_PASSED=0
WAIT_STRING="."

printf "\n${GREEN}Waiting for mysql to respond with updated schema $WAIT_STRING${PLAIN}"
while [ "$OUTPUT" -ne 0 ] && [ "$TIMEOUT" -gt 0 ]
do
docker exec -it $MYSQL_CONTAINER /bin/sh -c "mysql -u$USER -p$PASSWORD < /home/schema.sql" > /dev/null 2>&1
OUTPUT=$?
sleep 1s
TIMEOUT=$((TIMEOUT - 1))
TIME_PASSED=$((TIME_PASSED + 1))

if [ "$TIME_PASSED" -eq 5 ]; then
printf "${GREEN}.${PLAIN}"
TIME_PASSED=0
fi
done

if [ "$TIMEOUT" -le 0 ]; then
printf "\n\n${CYAN}Status: ${PLAIN}${RED}Failed to export schema. Terminating setup.${PLAIN}\n\n"
exit 1
fi
printf "\n${CYAN}Successfully exported schema to database.${PLAIN}\n"

## create the database
printf "\n${RED}>> Creating the database${PLAIN} ${GREEN}...${PLAIN}"
docker exec -it $MYSQL_CONTAINER /bin/sh -c "mysql -u$USER -p$PASSWORD -e \"DROP DATABASE IF EXISTS $DATABASE\"" > /dev/null 2>&1
docker exec -it $MYSQL_CONTAINER /bin/sh -c "mysql -u$USER -p$PASSWORD -e \"CREATE DATABASE $DATABASE\"" > /dev/null 2>&1
DATABASE_CREATED=$?
if [ "$DATABASE_CREATED" -ne 0 ]; then
printf "\n\n${CYAN}Status: ${PLAIN}${RED}Database could not be created. Terminating setup.${PLAIN}\n\n"
exit 1
fi
printf "\n${CYAN}Successfully created the database.${PLAIN}\n"

## set env variables for running test
printf "\n${RED}>> Setting env variables to run test${PLAIN} ${GREEN}...${PLAIN}"
export MYSQL_HOST=$HOST
export MYSQL_PORT=$PORT
export MYSQL_USER=$USER
export MYSQL_PASSWORD=$PASSWORD
export MYSQL_DATABASE=$DATABASE
printf "\n${CYAN}Env variables set.${PLAIN}\n"

printf "\n${CYAN}Status: ${PLAIN}${GREEN}Set up completed successfully.${PLAIN}\n"
printf "\n${CYAN}Instance url: ${YELLOW}mysql://$USER:$PASSWORD@$HOST/$DATABASE${PLAIN}\n"
printf "\n${CYAN}To run the test suite:${PLAIN} ${YELLOW}npm test${PLAIN}\n\n"

Loading