{"id":29117610,"url":"https://github.com/leoc11/elcy","last_synced_at":"2025-06-29T12:02:22.812Z","repository":{"id":24774578,"uuid":"102414404","full_name":"leoc11/elcy","owner":"leoc11","description":"ORM for Typescript and Javascript with Linq-like query syntax.","archived":false,"fork":false,"pushed_at":"2025-06-28T06:47:46.000Z","size":2509,"stargazers_count":10,"open_issues_count":10,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-28T07:36:27.399Z","etag":null,"topics":["database","elcy","entity-framework","javascript","linq","linq-to-entities","mssql","orm","sqlite","sqlserver","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leoc11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T00:29:03.000Z","updated_at":"2024-11-30T08:24:59.000Z","dependencies_parsed_at":"2022-07-25T14:22:08.326Z","dependency_job_id":null,"html_url":"https://github.com/leoc11/elcy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leoc11/elcy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoc11%2Felcy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoc11%2Felcy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoc11%2Felcy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoc11%2Felcy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leoc11","download_url":"https://codeload.github.com/leoc11/elcy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoc11%2Felcy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262395379,"owners_count":23304402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","elcy","entity-framework","javascript","linq","linq-to-entities","mssql","orm","sqlite","sqlserver","typescript"],"created_at":"2025-06-29T12:01:29.946Z","updated_at":"2025-06-29T12:02:17.923Z","avatar_url":"https://github.com/leoc11.png","language":"TypeScript","readme":"# Elcy\n[![codecov](https://codecov.io/gh/leoc11/elcy/branch/master/graph/badge.svg)](https://codecov.io/gh/leoc11/elcy)\n[![Build Status](https://travis-ci.org/leoc11/elcy.svg?branch=master)](https://travis-ci.org/leoc11/elcy)\n[![CLA assistant](https://cla-assistant.io/readme/badge/leoc11/elcy)](https://cla-assistant.io/leoc11/elcy)\n[![Dependency Status](https://david-dm.org/leoc11/elcy.svg)](https://david-dm.org/leoc11/elcy)\n[![devDependency Status](https://david-dm.org/leoc11/elcy/dev-status.svg)](https://david-dm.org/leoc11/elcy#info=devDependencies)\n\nElcy is an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping) \nfor typescript and javascript. Elcy is highly influenced by [Entity Framework](https://www.asp.net/entity-framework) and [NHibernate](http://nhibernate.info/).\n\n## Installation\nTo be updated...\n\n## Supported Database\n- Sql Server\n- Sqlite (not yet)\n\n## How to use\n\n### Create the Model\n\nEntity on your model is mark with `@Entity` class decorator. \n\nTo add database columns, you simply need to add decorator to your entity properties. Elcy has several column decorator for defining your column with specific column type:\n- `@StringColumn` : string column type.\n- `@BooleanColumn` : boolean column type.\n- `@NumberColumn` : integer column type.\n- `@DecimalColumn` : decimal column type.\n- `@ApproximateNumberColumn` : approximate number column type. ex: float\n- `@IdentifierColumn` : uuid column type.\n- `@DateColumn` : date column type.\n- `@EnumColumn` : *not implemented yet*\n- `@EmbeddedColumn` : *not implemented yet*\n\nHere several other decorator for entity property:\n- `@CreatedDate`: a date column type used to store entity creation date.\n- `@ModifiedDate`: a date column type used to store entity last modified date.\n- `@ColumnDescription`: add description to column.\n- `@DeletedColumn`: a boolean column type used for soft delete indicator.\n- `@NullableColumn`: mark column nullable.\n- `@PrimaryKey`: mark column as one of the entity primary key.\n\nExample:\n```typescript\nimport {Entity} from \"elcy/Decorator/Entity\";\nimport { PrimaryKey } from \"Elcy/Decorator/Column/PrimaryKey\";\nimport { NumberColumn } from \"Elcy/Decorator/Column/NumberColumn\";\nimport { DateColumn } from \"Elcy/Decorator/Column/DateColumn\";\nimport { IdentifierColumn } from \"Elcy/Decorator/Column/IdentifierColumn\";\nimport { UUID } from \"Elcy/Data/UUID\";\n\n@Entity()\nexport class Order {\n    @PrimaryKey()\n    @IdentifierColumn()\n    public OrderId: UUID;\n\n    @NumberColumn({ columnType: \"bigint\" })\n    public Amount: number;\n\n    @DateColumn()\n    public OrderDate: Date;\n    @CreatedDate()\n    public CreatedDate: Date;\n    @ModifiedDate()\n    public ModifiedDate: Date;\n    @DeletedColumn()\n    public isDeleted: boolean;\n}\n```\n\n### Create a Context\n\na Context represents a session with the database, allowing us to query and save data. Define a context that derives from `Elcy/Data/DbContext` and exposes a typed DbSet\u003cTEntity\u003e for each class in our model. Elcy has defined DbContext that you could used for each support db under `Elcy/Driver`.\n\nExample:\n```typescript\nimport { MssqlDbContext } from \"Elcy/Driver/Mssql\";\n\nexport class MyDb extends MssqlDbContext {\n    constructor() {\n        super(() =\u003e new MssqlDriver({\n            host: \"localhost\\\\SQLSERVER\",\n            database: \"mydb\",\n            port: 1433, // example\n            user: \"xxx\",\n            password: \"xxx\",\n        }));\n    }\n    public entityTypes = [Order]; // all entities that will be loaded using this context.\n    public orders: DbSet\u003cOrder\u003e = this.set(Order); // exposed typed DbSet for Order model.\n}\n```\n\n### Reading Data\n\nElcy used Linq-like syntax to read data from database. Example:\n\n```typescript\n(\n    async() =\u003e {\n        const db = new MyDb();\n\n        // select top 10 order with Amount \u003e 10 order by amount desc.\n        const orders = await db.orders.take(10).where(o =\u003e o.Amount \u003e 10).orderBy([o =\u003e o.Amount, \"DESC\"]).toArray();\n\n        // count all orders\n        const count = await db.orders.count();\n        \n        // where with parameter\n        const maxAmount = 10;\n        const count = await db.orders.parameters({ maxAmount }).where(o =\u003e o.Amount \u003c maxAmount).count();\n    }\n)();\n```\n\nBelow are the supported query expression syntax:\n- `where(predicate: (item: T) =\u003e boolean): Queryable\u003cT\u003e`\n- `distinct(): Queryable\u003cT\u003e`\n- `include(...includes: Array\u003c(item: T) =\u003e any\u003e): Queryable\u003cT\u003e`\n- `orderBy(...selectors: IQueryableOrderDefinition\u003cT\u003e[]): Queryable\u003cT\u003e`\n- `skip(skip: number): Queryable\u003cT\u003e`\n- `take(take: number): Queryable\u003cT\u003e`\n- `select\u003cTReturn\u003e(selector: ((item: T) =\u003e TReturn)): Queryable\u003cTReturn\u003e`\n- `selectMany\u003cTReturn\u003e(selector: (item: T) =\u003e TReturn[]): Queryable\u003cTReturn\u003e`\n- `groupBy\u003cK\u003e(keySelector: (item: T) =\u003e K): Queryable\u003cIGroupArray\u003cT, K\u003e\u003e`: limitation. groupBy(..).toArray() will not work.\n- `union(array2: Queryable\u003cT\u003e, isUnionAll?: boolean): Queryable\u003cT\u003e`\n- `intersect(array2: Queryable\u003cT\u003e): Queryable\u003cT\u003e`\n- `except(array2: Queryable\u003cT\u003e): Queryable\u003cT\u003e`\n- `toArray()`\n- `sum()`\n- `count()`\n- `max()`\n- `min()`\n- `avg()`\n- `all()`\n- `any()`\n- `first()`\n- `innerJoin`: *not yet supported*\n- `rightJoin`: *not yet supported*\n- `leftJoin`: *not yet supported*\n- `fullJoin`: *not yet supported*\n- `pivot`: *not yet supported*\n\n### Writing Data\n\nCreate:\n```typescript\n(\n    async() =\u003e {\n        const db = new MyDb();\n\n        // example 1: create and attach\n        const order = new Order();\n        order.OrderId = UUID.new();\n        order.Amount = 10;\n        db.add(order);\n\n        // example 2\n        const order2 = db.orders.new(UUID.new());\n        order2.Amount = 10;\n\n        db.saveChanges();\n    }\n)();\n```\n\nUpdate\n```typescript\n(\n    async() =\u003e {\n        const db = new MyDb();\n\n        const order = db.orders.first();\n        order.Amount += 1;\n        \n        await db.saveChanges();\n    }\n)();\n```\n\nDelete\n```typescript\n(\n    async() =\u003e {\n        const db = new MyDb();\n\n        const order = db.orders.first();\n        db.delete(order);\n        await db.saveChanges();\n    }\n)();\n```\n\n### Transaction\n\n```typescript\n(\n    async() =\u003e {\n        const db = new MyDb();\n\n        await db.transaction(o =\u003e {\n            // your code goes here\n        });\n    }\n)();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoc11%2Felcy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleoc11%2Felcy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoc11%2Felcy/lists"}