Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-sqlite-generator

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-sqlite-generator

Generate sqlite SQL queries from typescript interfaces

  • 0.0.26
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ts-sqlite-generator

install packages

yarn add -D ts-sqlite-generator typescript 

checkout example and run it

See example folder. Clone this repo and run 'yarn example'

prepare interface

have at least one interface with doc tag @sqlite_entry. This tag indicates that this interface should be able to be inserted without any referencing foreign keys. For example in src/store/models.ts:

/**
 * @sqlite_entry.
 */
interface Phase {
  name: string;
  phaseId: number;
  articles: Article[];
  optionalFieldsWork?: boolean;
}

interface Article {
  articleId: number;
  title: string;
  /**
   * @sqlite_index
   *
   */
  url: string;
  content: string;
  type: ArticleType;
  position: ArticlePosition;
  compoundType: CompoundType;
}

enum ArticleType {
  A,
  B,
  C
}

type ArticlePosition = "left" | "center" | "right";

interface SubTypeA {
  a: string;
}

interface SubTypeB {
  b: string;
}

type CompoundType = SubTypeA | SubTypeB;

create schema generator script

add a script file, for example 'scripts/generateSchemas.ts':

import path from 'path';
import { generator } from 'ts-sqlite-generator typescript';

generator(
  [path.join(__dirname, "models.ts")],
  path.join(__dirname, "../tsconfig.json"),
  path.join(__dirname, "__generated__/schema.ts"),
  path.join(__dirname, "__generated__/helpers.ts")
);

run with ts-node

yarn ts-node -T scripts/generateSchemas.ts

output

this results in queries being generated (CREATE TABLE, INSERT, REPLACE)

FAQs

Package last updated on 02 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc