Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pjt3591oo/typeorm-m-m-model
https://github.com/pjt3591oo/typeorm-m-m-model
orm typeorm typescript
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pjt3591oo/typeorm-m-m-model
- Owner: pjt3591oo
- Created: 2021-08-01T06:17:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-01T06:18:28.000Z (over 3 years ago)
- Last Synced: 2024-11-06T23:34:29.609Z (3 months ago)
- Topics: orm, typeorm, typescript
- Language: TypeScript
- Homepage: https://blog.naver.com/pjt3591oo/222453288846
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Awesome Project Build with TypeORM
Steps to run this project:
1. Run `npm i` command
2. Setup database settings inside `ormconfig.json` file
3. Run `npm start` command```sql
CREATE DATABASE test;
USE test;CREATE TABLE post (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
title VARCHAR(255) NOT NULL
);CREATE TABLE tag (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
color CHAR(6) NOT NULL DEFAULT "000000"
);CREATE TABLE tagging (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
postId INT NOT NULL,
tagId INT NOT NULL,
FOREIGN KEY (postId) REFERENCES post (id),
FOREIGN KEY (tagId) REFERENCES tag (id)
);DESC post;
DESC tag;
DESC tagging;SHOW INDEX FROM tagging;
# Insert: post table
INSERT INTO post(title) VALUES("title 1");
INSERT INTO post(title) VALUES("title 2");
INSERT INTO post(title) VALUES("title 3");
INSERT INTO post(title) VALUES("title 4");
INSERT INTO post(title) VALUES("title 5");
INSERT INTO post(title) VALUES("title 6");
INSERT INTO post(title) VALUES("title 7");
INSERT INTO post(title) VALUES("title 8");# Insert: tag
INSERT INTO tag (name, color) VALUES("dev", "ff0000"); # 1
INSERT INTO tag (name, color) VALUES("test", "f0f000"); # 2
INSERT INTO tag (name, color) VALUES("ui/ux", "00ff00"); # 3
INSERT INTO tag (name, color) VALUES("tool", "0000ff"); # 4
INSERT INTO tag (name, color) VALUES("javascript", "222222"); # 5
INSERT INTO tag (name, color) VALUES("python", "888888"); # 6# Insert: tagging
INSERT INTO tagging (postId, tagId) VALUES(1, 1);
INSERT INTO tagging (postId, tagId) VALUES(1, 5);
INSERT INTO tagging (postId, tagId) VALUES(2, 1);
INSERT INTO tagging (postId, tagId) VALUES(2, 2);
INSERT INTO tagging (postId, tagId) VALUES(2, 3);
INSERT INTO tagging (postId, tagId) VALUES(2, 5);
INSERT INTO tagging (postId, tagId) VALUES(5, 2);
INSERT INTO tagging (postId, tagId) VALUES(5, 4);SELECT * FROM post;
SELECT * FROM tag;
SELECT * FROM tagging;EXPLAIN SELECT post.id, post.title, tagging.* FROM post INNER JOIN tagging ON post.id = tagging.postId LIMIT 3;
SELECT
post.id, post.title, tag.name, tag.color
FROM
post
INNER JOIN
tagging
INNER JOIN
tag
ON
post.id = tagging.postId AND tag.id = tagging.tagId
ORDER BY post.id ASC;SELECT
*
FROM
post
LEFT OUTER JOIN tagging
ON post.id = tagging.postId
LEFT OUTER JOIN tag
ON tag.id = tagging.tagId
ORDER BY post.id ASC
LIMIT 3;SELECT
*
FROM
(SELECT id, title FROM post limit 3 OFFSET 3) as post
LEFT OUTER JOIN tagging
ON post.id = tagging.postId
LEFT OUTER JOIN tag
ON tag.id = tagging.tagId;SELECT
*
FROM
(SELECT * FROM post LIMIT 3) AS post
LEFT OUTER JOIN tagging
ON post.id = tagging.postId
LEFT OUTER JOIN tag
ON tag.id = tagging.tagId
ORDER BY post.id ASC;SELECT
*
FROM
post
LEFT OUTER JOIN tagging
ON post.id = tagging.postId
LEFT OUTER JOIN tag
ON tag.id = tagging.tagId
WHERE post.id in (
SELECT * FROM (
SELECT id FROM post LIMIT 3
) as post
)
ORDER BY post.id ASC;# 1235 error: Error Code: 1235. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
SELECT * FROM post WHERE id IN (SELECT id FROM post LIMIT 3);
```