-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from cyjake/docs-data-types-dts
docs: DataTypes definitions in d.ts
- Loading branch information
Showing
3 changed files
with
140 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { strict as assert } from 'assert'; | ||
import Realm, { Bone, DataTypes } from '../..'; | ||
|
||
describe('=> Data types (TypeScript)', function() { | ||
const { STRING, TEXT, BLOB } = DataTypes; | ||
|
||
it('Bone.DataTypes', async function() { | ||
assert.equal(Bone.DataTypes, DataTypes); | ||
}); | ||
|
||
it('realm.Bone.DataTypes', async function() { | ||
const realm = new Realm({ | ||
dialect: 'sqlite', | ||
database: '/tmp/leoric.sqlite3', | ||
}); | ||
// should be mixed with dialect overrides | ||
assert.notEqual(realm.Bone.DataTypes, DataTypes); | ||
}) | ||
|
||
it('STRING', async function() { | ||
assert.equal(STRING(255).toSqlString(), 'VARCHAR(255)'); | ||
}); | ||
|
||
it('TEXT', async function() { | ||
assert.equal(TEXT('long').toSqlString(), 'LONGTEXT'); | ||
}); | ||
|
||
it('BLOB', async function() { | ||
assert.equal(BLOB('medium').toSqlString(), 'MEDIUMBLOB'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
type LENGTH_VARIANTS = 'tiny' | '' | 'medium' | 'long'; | ||
|
||
interface INVOKABLE<T> { | ||
(length: LENGTH_VARIANTS): T; | ||
(length: number): T; | ||
} | ||
|
||
export default class DataType { | ||
toSqlString(): string; | ||
|
||
static STRING: typeof STRING & INVOKABLE<STRING>; | ||
static INTEGER: typeof INTEGER & INVOKABLE<INTEGER>; | ||
static BIGINT: typeof BIGINT & INVOKABLE<BIGINT>; | ||
static TEXT: typeof TEXT & INVOKABLE<TEXT>; | ||
static BLOB: typeof BLOB & INVOKABLE<BLOB>; | ||
static JSON: typeof JSON & INVOKABLE<JSON>; | ||
static JSONB: typeof JSONB & INVOKABLE<JSONB>; | ||
static BINARY: typeof BINARY & INVOKABLE<BINARY>; | ||
static VARBINARY: typeof VARBINARY & INVOKABLE<VARBINARY>; | ||
static DATE: typeof DATE & INVOKABLE<DATE>; | ||
static DATEONLY: typeof DATEONLY & INVOKABLE<DATEONLY>; | ||
static BOOLEAN: typeof BOOLEAN & INVOKABLE<BOOLEAN>; | ||
} | ||
|
||
declare class STRING extends DataType { | ||
dataType: 'varchar'; | ||
length: number; | ||
constructor(length: number); | ||
} | ||
|
||
declare class INTEGER extends DataType { | ||
dataType: 'integer' | 'bigint'; | ||
length: number; | ||
constructor(length: number); | ||
get UNSIGNED(): this; | ||
get ZEROFILL(): this; | ||
} | ||
|
||
declare class BIGINT extends INTEGER { | ||
dataType: 'bigint'; | ||
} | ||
|
||
declare class TEXT extends DataType { | ||
dataType: 'text'; | ||
length: LENGTH_VARIANTS; | ||
constructor(length: LENGTH_VARIANTS); | ||
} | ||
|
||
declare class BLOB extends DataType { | ||
dataType: 'blob'; | ||
length: LENGTH_VARIANTS; | ||
constructor(length: LENGTH_VARIANTS) | ||
} | ||
|
||
declare class JSON extends DataType { | ||
dataType: 'text' | 'json'; | ||
} | ||
|
||
declare class JSONB extends JSON { | ||
dataType: 'json'; | ||
} | ||
|
||
declare class BINARY extends DataType { | ||
dataType: 'binary'; | ||
length: number; | ||
constructor(length: number); | ||
} | ||
|
||
declare class VARBINARY extends DataType { | ||
dataType: 'varbinary'; | ||
length: number; | ||
constructor(length: number); | ||
} | ||
|
||
declare class DATE extends DataType { | ||
dataType: 'date'; | ||
precision: number; | ||
timezone: boolean; | ||
constructor(precision: number, timezone?: boolean) | ||
} | ||
|
||
declare class DATEONLY extends DataType { | ||
dataType: 'dateonly'; | ||
} | ||
|
||
declare class BOOLEAN extends DataType { | ||
dataType: 'boolean' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters