Code Monkey home page Code Monkey logo

nuxt-typeorm's Introduction

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

nuxt-typeorm's People

Contributors

will2hew avatar

Stargazers

letovsk1y avatar  avatar Jakub Andrzejewski avatar Neil Richter avatar  avatar Louis F. avatar Brendon Matos avatar Sébastien Chopin avatar

Watchers

 avatar

nuxt-typeorm's Issues

TS decorators can't detect types

TypeORM can't seem to determine the type of the column variables, and need to be manually typed e.g. @Column({ type: "number"})

Access entities in frontend

There are currently Vite errors when attempting to import entities in the frontend. This would be a meaningful quality of life improvement to avoid having to re-create interfaces in frontend code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.