mirror of
https://github.com/strapi/strapi.git
synced 2025-11-14 01:02:04 +00:00
wip
This commit is contained in:
parent
d1cc5df7c5
commit
ba04122263
@ -2,6 +2,8 @@ import { isString } from 'lodash/fp';
|
|||||||
import type { Database } from '..';
|
import type { Database } from '..';
|
||||||
import type { ID } from '../types';
|
import type { ID } from '../types';
|
||||||
|
|
||||||
|
export type Repository = ReturnType<typeof createRepository>;
|
||||||
|
|
||||||
type Params = Record<string, unknown>;
|
type Params = Record<string, unknown>;
|
||||||
type Data = Record<string, unknown>;
|
type Data = Record<string, unknown>;
|
||||||
type Entity = {
|
type Entity = {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import { mapAsync } from '@strapi/utils';
|
|||||||
import * as types from '../utils/types';
|
import * as types from '../utils/types';
|
||||||
import { createField } from '../fields';
|
import { createField } from '../fields';
|
||||||
import { createQueryBuilder } from '../query';
|
import { createQueryBuilder } from '../query';
|
||||||
import { createRepository } from './entity-repository';
|
import { createRepository, Repository } from './entity-repository';
|
||||||
import { deleteRelatedMorphOneRelationsAfterMorphToManyUpdate } from './morph-relations';
|
import { deleteRelatedMorphOneRelationsAfterMorphToManyUpdate } from './morph-relations';
|
||||||
import {
|
import {
|
||||||
isPolymorphic,
|
isPolymorphic,
|
||||||
@ -55,6 +55,8 @@ import type { Database } from '..';
|
|||||||
import type { Meta } from '../metadata';
|
import type { Meta } from '../metadata';
|
||||||
import type { ID } from '../types';
|
import type { ID } from '../types';
|
||||||
|
|
||||||
|
export type EntityManager = ReturnType<typeof createEntityManager>;
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
where?: any;
|
where?: any;
|
||||||
filters?: any;
|
filters?: any;
|
||||||
@ -257,7 +259,7 @@ const processData = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const createEntityManager = (db: Database) => {
|
export const createEntityManager = (db: Database) => {
|
||||||
const repoMap: Record<string, any> = {};
|
const repoMap: Record<string, Repository> = {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async findOne(uid: string, params: Params) {
|
async findOne(uid: string, params: Params) {
|
||||||
@ -1502,9 +1504,5 @@ export const createEntityManager = (db: Database) => {
|
|||||||
|
|
||||||
return repoMap[uid];
|
return repoMap[uid];
|
||||||
},
|
},
|
||||||
|
|
||||||
clearRepositories() {
|
|
||||||
repoMap.clear();
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import type { Knex } from 'knex';
|
import type { Knex } from 'knex';
|
||||||
|
|
||||||
import { Dialect, getDialect } from './dialects';
|
import { Dialect, getDialect } from './dialects';
|
||||||
import { createSchemaProvider } from './schema';
|
import { createSchemaProvider, SchemaProvider } from './schema';
|
||||||
import { createMetadata, Metadata } from './metadata';
|
import { createMetadata, Metadata } from './metadata';
|
||||||
import { createEntityManager } from './entity-manager';
|
import { createEntityManager, EntityManager } from './entity-manager';
|
||||||
import { createMigrationsProvider } from './migrations';
|
import { createMigrationsProvider, MigrationProvider } from './migrations';
|
||||||
import { createLifecyclesProvider } from './lifecycles';
|
import { createLifecyclesProvider, LifecycleProvider } from './lifecycles';
|
||||||
import { createConnection } from './connection';
|
import { createConnection } from './connection';
|
||||||
import * as errors from './errors';
|
import * as errors from './errors';
|
||||||
import { Callback, transactionCtx } from './transaction-context';
|
import { Callback, transactionCtx } from './transaction-context';
|
||||||
@ -36,17 +36,21 @@ class Database {
|
|||||||
|
|
||||||
metadata: Metadata;
|
metadata: Metadata;
|
||||||
|
|
||||||
schema: ReturnType<typeof createSchemaProvider>;
|
schema: SchemaProvider;
|
||||||
|
|
||||||
migrations: ReturnType<typeof createMigrationsProvider>;
|
migrations: MigrationProvider;
|
||||||
|
|
||||||
lifecycles: ReturnType<typeof createLifecyclesProvider>;
|
lifecycles: LifecycleProvider;
|
||||||
|
|
||||||
entityManager: ReturnType<typeof createEntityManager>;
|
entityManager: EntityManager;
|
||||||
|
|
||||||
static transformContentTypes: typeof transformContentTypes;
|
static transformContentTypes = transformContentTypes;
|
||||||
|
|
||||||
static init: (config: DatabaseConfig) => Promise<Database>;
|
static async init(config: DatabaseConfig) {
|
||||||
|
const db = new Database(config);
|
||||||
|
await validateDatabase(db);
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(config: DatabaseConfig) {
|
constructor(config: DatabaseConfig) {
|
||||||
this.metadata = createMetadata(config.models);
|
this.metadata = createMetadata(config.models);
|
||||||
@ -160,12 +164,4 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move into strapi
|
|
||||||
Database.transformContentTypes = transformContentTypes;
|
|
||||||
Database.init = async (config: DatabaseConfig) => {
|
|
||||||
const db = new Database(config);
|
|
||||||
await validateDatabase(db);
|
|
||||||
return db;
|
|
||||||
};
|
|
||||||
|
|
||||||
export { Database, errors };
|
export { Database, errors };
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
interface Attribute {
|
import type { Model } from '../types';
|
||||||
|
|
||||||
|
export interface Attribute {
|
||||||
type: string;
|
type: string;
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContentType {
|
export interface ContentType {
|
||||||
|
uid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
collectionName: string;
|
collectionName: string;
|
||||||
attributes: Record<string, Attribute>;
|
attributes: Record<string, Attribute>;
|
||||||
@ -26,7 +29,7 @@ const transformAttribute = (attribute: Attribute) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: model logic outside DB
|
// TODO: model logic outside DB
|
||||||
export const transformContentTypes = (contentTypes: ContentType[]) => {
|
export const transformContentTypes = (contentTypes: ContentType[]): Model[] => {
|
||||||
return contentTypes.map((contentType) => {
|
return contentTypes.map((contentType) => {
|
||||||
const model = {
|
const model = {
|
||||||
...contentType,
|
...contentType,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user