nuxt-typeorm
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

⚠️ 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,
  };
});

Readme

Keywords

none

Package Sidebar

Install

npm i nuxt-typeorm

Weekly Downloads

2

Version

0.0.8

License

MIT

Unpacked Size

7.93 kB

Total Files

15

Last publish

Collaborators

  • will2hew