0.0.8 • Published 3 months ago

nuxt-typeorm v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

⚠️ Under Active Development ⚠️

Nuxt TypeORM

npm version npm downloads License Nuxt

A Nuxt module to make it easy to use TypeORM in your project

Usage

Installation

  1. Add nuxt-typeorm dependency to your project
npm install nuxt-typeorm
  1. Add nuxt-typeorm to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: ["nuxt-typeorm"],
});
  1. Add your TypeORM and TypeScript configuration to nuxt.config.ts
typeorm: {
    type: "sqlite",
    database: "db.sqlite",
    synchronize: true,
    logging: false,
  },
  nitro: {
    esbuild: {
      options: {
        tsconfigRaw: {
          compilerOptions: {
            emitDecoratorMetadata: true,
            experimentalDecorators: true,
          },
        },
      },
    },
    typescript: {
      tsConfig: {
        compilerOptions: {
          emitDecoratorMetadata: true,
          experimentalDecorators: true,
          strictPropertyInitialization: false,
        },
      },
    },
  }
  1. Create an entity
// server/entities/user.entity.ts
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity("user")
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: "varchar" })
  firstName: string;

  @Column({ type: "varchar" })
  lastName: string;
}
  1. Export the entities
// server/entities/entities.ts
import { User } from "./user.entity";

export const entities = [User];
  1. You're done! nuxt-typeorm provides a getRepository helper function
// server/api/users.get.ts

import { getRepository } from "#typeorm";

export default defineEventHandler(async (event) => {
  const userRepository = await getRepository(User);

  const users = await userRepository.find();

  return {
    users,
  };
});
0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago