Socket
Socket
Sign inDemoInstall

ts-sqlite-generator

Package Overview
Dependencies
5
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-sqlite-generator

Generate sqlite SQL queries from typescript interfaces


Version published
Maintainers
1
Install size
536 kB
Created

Readme

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

Last updated on 02 Jul 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc